2

I want to copy text from vim, eg. by selecting in visual mode, then ctrl+insert and I'd like to have the copied text in system buffer, so I can paste it anywhere I like with eg ctrl+v. Is it possible somehow?

Problem arises when I need to copy long text from vim window to buffer. I cannot simply select it all with a mouse and then copy it, because the text doesn't fit in the window.

3 Answers 3

2

Yes. Vim has references to the system clipboards as registers, which you can use like any other registers.

The main clipboard is *, so you can highlight in visual mode, then type "*y. If you're using X11 you can copy to the X11 buffer using the + register. Lastly, you can reassign the default register to the clipboard register with :set clipboard=unnamed. If you do this then any copies, yanks, or kills will automatically go to the system clipboard without you manually specifying the register first.

1
  • It worked first time after I rebooted my PC. But after that when I've used console buffer, system buffer, etc, they seems to have mixed up. So now when I do "*y, text doesn't go to system buffer. But X11 buffer + still working fine. Thanks anyway.
    – user69817
    Commented Jul 7, 2011 at 10:44
2

The visual selection (v, V, or CTRL+V) can automatically be copied to the X11 selection (* buffer).

In non-gui mode the clipboard option controls this (only supported if +xterm_clipboard appears when you type vim --version). In GUI mode guioptions controls it.

This makes all Visual mode selections automatically go to the X11 primary selection:

set clipboard+=autoselect<br>
set guioptions+=a

This turns it off:

set clipboard-=autoselect<br>
set guioptions-=a

See :help 'clipboard' (single quotes required).

0

On OS X you can use pbcopy/pbpaste command-line tools to achieve that.

For instance, to copy the current line, run:

:.!pbcopy "Copy current line clipboard

To copy the whole file:

:!echo "%:p" | pbcopy

Or to copy selected text (using visual mode via: v/V), type !pbcopy after selecting text, so it becomes: :'<,'>!pbcopy, so it'll copy the text into the Clipboard.

See: Mac OS X clipboard sharing

For Linux, use xclip, gpm or something similar.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .