Copying out of Vim

September 29, 2010

Occasionally I need to be able to copy text out of a Vim terminal window into another application. Setting mouse=a in my .vimrc disabled the terminal windows copy and paste functionality. However, Vim does have a key combination which will yank into the global clipboard. The keys are:

"+y (copy)
"+x (cut)
"+p (paste)

Note that you need the quote, the plus and the letter.

Unfortunately, this only works if your vim is compiled with +xterm_clipboard. Run the following to see if it is:

vim --version | grep xterm

If you see +xterm_clipboard in the output you are good to go, if it says -xterm_clipboard or is missing then this will not work.

For those of you without this an alternative is to hold down shift while dragging the mouse which allows the selection to be copied by the terminal.



  1. Did not work for me,

  2. Doesn’t work for me anymore either. My default configuration has :set mouse=a which allows moving the cursor and triggering visual mode in vim. However, if I need to copy out of vim to the global config I now have to run :set mouse=r which then lets highlighting copy to the global clipboard. I then do :set mouse=a to go back to how it was before. Pretty annoying but not found another way yet,

  3. Spoke to soon. Hold shift down while dragging the mouse in ‘a’ mode and the selection acts like it’s in ‘r’ mode.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: