Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
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 '11 at 19:21
    
yes, gvim worked! –  Richard May 23 '11 at 19:29
add comment

2 Answers

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
share|improve this answer
add comment

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
share|improve this answer
    
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) –  Michael Mrozek May 23 '11 at 16:47
    
still not working with "+gy –  Richard May 23 '11 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.