-->

Copy and paste in vim via keyboard between differe

2019-03-09 15:21发布

问题:

Can anyone help me with this: I'm trying to figure out how to copy and paste text between 2 different instances of vim on different terminals (using iterm2 or mac terminal). I can do it using the mouse if I do ":set mouse=a" but I'd like to be able to do it using the keyboard.

I've googled around and it says you can use the "* or "+ registers to copy/paste to/from the system clipboard, but when I type * or + in vim, the mac makes one of those sounds it makes when you can't do something. I've also done ":set clipboard=unnamed" but that hasn't worked either.

I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.

Thanks for the help

回答1:

Could you add the output of :version?

I can yank with yy or y in one Vim instance running in Terminal.app window A and put with p or P in another Vim instance running in Terminal.app window B with this line in my ~/.vimrc:

set clipboard+=unnamed

without using specific clipboard registers (* or +).

And why do you have two Vim instances running in different terminals? SSH/local? If one is in an SSH session yanking/putting won't work because the two machines (local/remote) don't share the same clipboard(s).

EDIT

I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.

Since you are using Mac OS X's default Vim my opinion is that you shouldn't need to re-compile it or even compile anything as it often leads to more problem's than it's worth.

Instead, download the latest MacVim build and use the (CLI) Vim executable within MacVim's bundle: it has all the same functionalities as MacVim (within the constraints of the CLI, of course).

Add this line to your ~/.bashrc or ~/.profile or wherever you are used to put aliases and custom bash functions:

alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'


回答2:

If you want to copy an entire file into your target file.

Open your target file in vim.

Put your cursor where you want it and type the following:

:r /path_to_file/file.ext

This will copy an entire file to where your cursor is...