Reputation: 430
I would like to copy a selected word that the cursor is on to the clipboard. Is there a way to do this.
Upvotes: 2
Views: 803
Reputation: 1152
Follow instruction in https://stackoverflow.com/a/65666057/9384511
Once you have set up your vim as per above link, you will be able to copy single or multiple lines from vim to clipboard by pressing Ctrlc. And paste from clipboard to vim by pressing Ctrlp
Now to copy just a single word to clipboard press bveCtrlc
Upvotes: 0
Reputation: 365
First at all you must check if the clipboard feature on your VIM is enable or not. For that use the --version parameter (vim --version)
If not (-clipboard), you can use a gtk vim edition or compile VIM manually.
If yes (+clipboard), in normal mode "+yiw
on your word for copy it in your clipboard.
Upvotes: 1
Reputation: 15105
If support for clipboard is built into your Vim, clipboard is mapped to register *, so you use it the same as any other register. So, for example, to copy the word under cursor to clipboard you do "*yiw
. To copy current line "*yy
. To paste from clipboard "*p
Upvotes: 3
Reputation: 3784
Perhaps you just want to do this:
viwp
which will visually select a new word, and paste over it.
Now, if you don't want to lose your register when doing this, you can also put in your vimrc:
xnoremap p pgvy
Upvotes: 1