Robert Webb schrieb:
> Here's what seems like a really stupid question:
>
> What's the simplest way to move the cursor to the start of the word under
> it?
> "Under it" includes the word after the cursor if there's no identifier under
> it.
>
> None of these quite work:
>
> b - The obvious choice, but won't work if the cursor is already on the first
> character or before it.
>
> wb - My usual method. Won't work if the cursor is in the space before the
> word though (nor on a single-character word at the end of the file, although
> I could live with that).
>
> eb - Won't work on last character of word.
>
> *# - OK, I guess this should work, but seems inefficient to do a search.
>
> I'm trying to avoid a more complicated piece of script for such a simple
> operation.
>
> Thanks, and sorry if it is a stupid question with an obvious answer :-)
Not a stupid question if you ask me ...
> Rob.
In fact, it's annoyingly difficult!
How about this one: goto (start of) word
:nn <silent> \gw :<C-U>call search('\w\>','c')<CR>b
It's basically eb , but will work if on the last character of the word.
But ... will not work on a single character word.
Another (more ambitious) try:
map <Leader>gw <Plug>sow
noremap <silent> <Plug>sow :<C-U>call Sow(0)<CR>
vnoremap <silent> <Plug>sow :<C-U>call Sow(1)<CR>
" move cursor to Start of word (the word returned by expand("<cword>"))
func! Sow(vmode)
if a:vmode
normal! gv
endif
let xw = expand("<cword>")
if xw != ""
call search('\k\>',"cW")
if strlen(xw) > 1
normal! b
endif
endif
endfunc
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---