Vim copy-paste to system buffer not behaving as ex

2019-03-22 16:49发布

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.

6条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-22 17:18

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?

查看更多
Evening l夕情丶
3楼-- · 2019-03-22 17:19

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.

查看更多
时光不老,我们不散
4楼-- · 2019-03-22 17:21

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.

查看更多
相关推荐>>
5楼-- · 2019-03-22 17:22

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

vim asd
"+y
:q
vim qwe
"+p
查看更多
叼着烟拽天下
6楼-- · 2019-03-22 17:34

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.

查看更多
小情绪 Triste *
7楼-- · 2019-03-22 17:37

Try this:

set clipboard=unnamed

It allows copying and pasting through the system clipboard.

查看更多
登录 后发表回答