4

How can I select the + register? I have problems following the instructions below to copy/paste text from vim to another vim:

In the vim, highlight, select + register, and yank (save) to it:
Shift-v
"+y

In the second vim, select + register, and paste from it:
"+p

I think I'm pressing the wrong keys. When it says "+y, do I simply hit the keys ", +, y in sequence? (That is, Shift+', Shift+=, y). It does not work for me.

I am using Red Hat and vim in an X11 terminal. And vim version is

$vim --version | grep xterm_clipboard
-xterm_clipboard -xterm_save
2
  • 2
    Can you use gvim, instead? That is how you can use the X clipboard to transfer text using the X clipboard. Yes, you use those exact keys. Your vim doesn't have xterm_clipboard support.
    – Keith
    May 23, 2011 at 19:21
  • yes, gvim worked!
    – Richard
    May 23, 2011 at 19:29

3 Answers 3

6

Vim uses the system cut-and-paste mechanism to copy text between instances. When you run vim in a terminal, it doesn't have direct access to any cut-and-paste mechanism. If vim is running in xterm or some other terminal that provides access to X selections and clipboard contents, vim can use that; however your vim binary is compiled without support for that feature.

If both vim instances are running on the same machine, you can use a temporary file to communicate:

:w ~/vim.tmp
:r ~/vim.tmp

If both vim instances are connected to the same X display (in that the DISPLAY environment variable points to the same X display, the vim programs themselves don't need to have any kind of X support), you can use the X selections via an external program such as xsel or xclip. You can omit the p or -selection primary or choose a different selection (-s/secondary or -b/clipboard). Use :w ! (note the space) to copy:

:w !xsel -ip
:w !xclip -i -selection primary

and :r! to paste:

:r !xsel -op
:r !xclip -o -selection primary
0

On Red Hat (and Fedora), use the /usr/bin/vimx command. The + register (system clipboard) will work if you use the vimx command.

vimx has support for the system clipboard compiled in:

$ vimx --version | grep xterm_clipboard
+eval            +mouse_dec       +startuptime     +xterm_clipboard

vimx is in the vim-X11 package, which also contains gvim.

Use this alias:

alias vim=/usr/bin/vimx
-1

Your examples use the + register. To use the ? register, simply use the same commands, replacing the + with ?.

for example:

"?y
"?p

If you're trying to paste between instances of vim using the system clipboard, you'll want to prepend a g to your commands, thus

"+gy
"+gp
3
  • I don't think he's talking about the ? register; the ? was just ending a sentence that contained a question. He's using the + register but needs it to work between vim instances (so your part about using the system clipboard will probably solve his problem) May 23, 2011 at 16:47
  • still not working with "+gy
    – Richard
    May 23, 2011 at 16:58
  • ? is not a supported register name. "?y does nothing Jan 10, 2017 at 19:41

You must log in to answer this question.

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