0

I have two Terminals with vim open, side by side. Each Terminal has a different file. I can yank and paste lines within one of these Terminals/files, but how do I paste the yanked lines from one Terminal/file into the other open Terminal/file?

Justin
  • 164
  • 7
  • 1
    You probably have your reasons for having two terminals with vim open, but have you considered running one instance of vim in one terminal with twice the width? You can open the second file as a buffer, side by side with the other file you are editing. For a couple sources on how, see buffers: http://vimcasts.org/episodes/working-with-buffers/ windows: http://vimcasts.org/episodes/working-with-windows/ – neallred Jan 09 '16 at 00:46
  • See here: https://stackoverflow.com/questions/5532878/how-to-copy-codes-in-vi-to-clipboard/14225889#14225889 – pfnuesel Jan 10 '16 at 07:59

3 Answers3

3

First, check if your Vim is built with clipboard support with:

:echo has('clipboard')

If you get a 0, install a proper Vim (but you didn't tell us what system you are on so we can't tell you how).

If you get a 1, use either "+y and "+p or "*y and "*p to yank and paste (again, we can't tell you which one without knowing more on your setup).

See :help register.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • So I have a MacOSX (El Capitan), and I got a 0 when i did :echo has('clipboard') – Justin Jan 08 '16 at 21:44
  • 1
    1. Download MacVim. 2. Put the bundled `mvim` somewhere in your `$PATH`. 3. Use `mvim -v` instead of `vim`. 4. Enjoy clipboard integration. – romainl Jan 08 '16 at 22:26
  • This will copy it to your clipboard. But then I have to press Ctrl + V in insert mode. I was hoping to yank and put directly across terminal tabs (but using the same program, vim). – gamesguru Mar 07 '23 at 18:31
1

You can also write to your clipboard using pbcopy if you do not have clipboard support in vim. If you highlight what you want in Visual mode and then type :w !pbcopy it will write to the clipboard. The command will actually look like this in practice: :'<,'>w !pbcopy because of the selected text.

yam
  • 66
  • 5
-1

You can simply Ctrl+shift+c your selection. Put yourself in insertion mode in your vim then Ctrl+shift+v and it should work.

Dridou
  • 1
  • 1