Monroy
Monroy

Reputation: 430

How to copy a selected word to the clipboard using VIM?

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

Answers (4)

ABN
ABN

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

Erms
Erms

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

Mad Wombat
Mad Wombat

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

Nicholas
Nicholas

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

Related Questions