Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy and paste in vim via keyboard between different mac terminals?

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

like image 537
Eddy Avatar asked Nov 15 '11 10:11

Eddy


People also ask

How do I copy and paste in vim terminals?

To copy from a terminal window press CTRL-W N (This is a capital N)1 or CTRL-\ CTRL-N (this is not a capital N) to get into normal mode. From there you can use all usual vim commands to copy and paste stuff. Entering insert mode will drop you back to your shell.

How do you paste in vim on a Mac?

Put (Paste)p will put whatever you have Yanked or Deleted into the doc wherever the cursor is currently located. If you have a line on the vim's clipboard (not the OS's clipboard) it will paste it on the line below the cursor. If just you have some characters, they will it will paste after the cursor.

How do I paste using keyboard in Vim?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do I copy and paste outside in Vim?

To copy text from outside applications into Vim editor, first copy the text using the usual Ctrl-C command then go to Vim editor and type "+p in Normal Mode. I find the above commands very tedious to type every time I copy-paste from outside Vim, so I mapped the Ctrl-y to copy and the Ctrl-p to paste in Vim.


1 Answers

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'
like image 70
romainl Avatar answered Sep 28 '22 09:09

romainl