11

I have a virtual Linux development environment running under VirtualBox and Vagrant. I use tmux and vim to setup multiple open vim instances. I'd like to be able to copy and paste between those instances.

I'm learning that clipboard functionality only comes with X11. How can I enable clipboard functionality between multiple vim instances in a command line only Linux environment?

Brent
  • 193
  • 1
  • 2
  • 5
  • 2
    http://unix.stackexchange.com/a/13671/70524, http://vi.stackexchange.com/a/2022/205 – muru Jul 16 '15 at 03:16

2 Answers2

4

As you're already using it, I'd recommend tmux as fully supports copy and paste - see the manual page for more information.

You can see the current key bindings by using the tmux list-keys command - look for the begin-selection, copy-selection and paste-buffer commands in that list.

By default, the bindings are:

  • [ - Start copy/paste mode
  • h, j, k, l - vi navigation keys to move the cursor
  • v - Start text selection (once selected, hit Enter to copy to the buffer for later pasting)
  • ] - Paste copied text

There are some limitations when using it with a curses-based application like vim (as tmux can't then manage scrolling) - you're not able to scroll back to previous output.

As an alternative (and if you're only copying between vim sessions), you can use a temporary file as a clipboard (you'll need to do this if you're not using X11). See this post suggested by @muru for further information.

mjturner
  • 7,082
  • 1
  • 26
  • 32
  • Few problems with this. It doesn't allow me to copy more than one screen full from a vim session. Secondly, I have line numbers setup on the left border of my vim session and this copies the line numbers as well. Thirdly, it doesn't share the copy with vim, so I can't use `p` or `P` to paste it in without being in insert mode which means it requires a few extra keystrokes to get things setup. It's useful to know for cutting and pasting from logs, but I think it's a poor replacement for clipboard functionality in vim. – Brent Jul 17 '15 at 00:40
  • Fair comment. I've added a little further information. I think the best option is to go with the temporary file (as per @Muru's links) – mjturner Jul 17 '15 at 07:33
0

Do not need to stick with clipboard if the expected behaviour is about store -> retrieve, the instruction originates from https://vim.fandom.com/wiki/Copy_and_paste_between_sessions_using_a_temporary_file

"custom copy'n'paste

vmap <C-c> :w! ~/.vbuf<CR>      "copy the current visual selection to ~/.vbuf
nmap <C-c> :.w! ~/.vbuf<CR>     "copy the current line to the buffer file if no visual selection
nmap <C-v> :r ~/.vbuf<CR>       "paste the contents of the buffer file

Once we have content stored in ~/.vbuf, we have all the freedom to retrieve the content in our own way.

Katsum0to
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 13 '23 at 14:58