Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from Jul 6 '11 at 13:24

This question came from our site for system and network administrators.

up vote 2 down vote accepted

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.

share|improve this answer
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 Jul 7 '11 at 10:44

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).

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

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