views:

1404

answers:

6

I'm having a headache trying to figure out why vim isn't copying to a system buffer.

Here's my workflow:

vim asd
y1y
:q
vim qwe
p

On computerA and computerB, this works as I want it to: the line yanked from the file asd is put into the file qwe.

On computerC, this doesn't work.

All systems are running Ubuntu 8.04. computerA has the vim-full package installed, computerB and computerC have the vim package installed. computerA has xorg installed, is using the fluxbox window manager, and is accessed locally. computerB and computerC don't have X, and I'm sshing into both of them.

I've done a lot of reading and thought it was because computerC was compiled with -clipboard, but I ran vim --version on all three computers and only computerA was compiled with +clipboard.

Am I missing something obvious? I believe the user's .vimrc and the global vimrc files are the same. I can post output of vim --version and contents of vimrc files if that would help.

+1  A: 

Take a look in .viminfo if the last thing you yanked was hi it should contain:

Registers:

""0 LINE 0 hi

Maybe the file permissions are messed up?

Timothy Pratley
Thanks Timothy, file permissions were indeed borked!
nfm
A: 

Try this:

set clipboard=unnamed

It allows copying and pasting through the system clipboard.

Mosh
The OP has stated that only computerA is compiled with `+clipboard`, so this won't work for computerB or computerC.
Al
+2  A: 

Vim by default doesn't copy to a system buffer. The only way that it would remember the contents is if the multiple instances of vim use the same .viminfo file. It's possible that the .viminfo file isn't being written due to file permissions or due to a different setting in 'viminfo' (the option).

For more information on the viminfo configuration, see

:help 'viminfo'

To look at your current configuration on each computer, do:

:set viminfo?

As an aside, if you want to use the system clipboard (which must be present, so you'd need to do ssh -X), you can use:

:set clipboard+=unnamed

Then all copy and paste operations will use the X11 selection buffer. Of course, you need vim compiled with +clipboard for this to work, so it won't solve your immediate problem. See:

:help 'clipboard'

for more information.

Perhaps you could post the result of the following on each computer?

:set viminfo?
:set clipboard?

This would help us to diagnose the problem in more detail. Could you also try:

vim asd
"ayy
:q
vim qwe
"ap

This will use register a instead of the unnamed register.

Al
Thanks Al, you were right on the ball. ~/.viminfo was owned by root:root - I must have sudoed or something the first time I used vim? Was barking up the wrong tree with the system clipboard, thanks for the answer and the new knowledge!
nfm
A: 

It doesn't exactly solve your problem, but a perfectly fine workaround would be

vim asd
y1y
:sp qwe
p
:q

Which will open asd and yank from it (obviously), then split-open qwe, put your just-yanked item, and close the split-opened file. With this approach, there's no need to close the document you're working on a start a new instance of Vim.

And if you don't like the horizontal split, :vsp makes a vertical split, which can sometimes be easier to read/use.

Mark Rushakoff
Leonid Shevtsov
`:gT` and `:gt` gives me E492 (not an editor command), but `:tabn` (no arguments) and `:tabp` work (using Vim 7.2). I usually prefer splits because I can see both documents at once.
Mark Rushakoff
+1  A: 

Why not use "+y and "+p, they work directly with the system's clipboard buffer

vim asd
"+y
:q
vim qwe
"+p
Leonid Shevtsov
-1: From the original post: "only computerA was compiled with +clipboard". This will therefore only work on computerA (unless it happens to be held in the unnamed register through the viminfo mechanism, which the OP has already stated doesn't work).
Al
A: 

OK, I don't know about the system buffer issue, but what about simply opening the new file with :e filename, then pasting, then saving and :e #ing your way back to the original file if needed? Yeah I know, tabs and splits are cool, but simple can do the job too.

You could also use ex, either from the target file to read the content to be included via the :r command supplying a line range, or from the source file to append the selected text (either via simple line number/range or the almighty g command) with :w >> filename.

Pif