On Thu, March 11, 2010 9:24 am, Neshama wrote:
> Is it possible to (visually) select a word under the cursor ?
>
> The reason I need that is to easily copy and paste words under the
> cursor, without having to manually select them with 'v' first (which
> is slow).
>
> I know that '*' and '#' finds me occurrences of the word under the
> cursor, so I guess VIM already have the underlying brain to also
> select the word.

If you do
:set guioptions+=a
vim will automatically copy the visual selection into the clipboard. Now
with a little mapping, vim will copy your search phrase into the
clipboard:
:nnoremap * g*:let @+=@/<cr><c-l>

(You would probably also want to map #). The drawback is, that this uses
g* to search which means the search won't consider word boundaries (*
searches for the word under the cursor, while g* searches for the
pattern under the cursor and thus also finds submatches, e.g. if you
press * on a, this will only find the word a, while g* on a also matches
ab). To fix this, you could may be use this mapping:

:nnoremap * *:let @+=@/[2:-3]<cr><c-l>

(which removes the word-boundary strings from the search string and puts
the result in your clipboard.)

A different approach would be to map */# to have the word selected
automatically. Something like this:
:nnoremap * viw<esc>*

This has the disadvantage to move your cursor to the first letter in the
selected word, which may be undesired.

All this only works with gvim, though.

regards,
Christian
-- 
:wq

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to