0

I posted this question on StackOverflow first, as I did not know about "Vi and Vim beta".

How to augment Vim yank and paste, so when I yank, Vim writes the content to a file? When I paste, it uses the content from the file. I want to have a system wide file which serves as a global buffer.

Context: I run Vim in different tmux splits on a remote server (over ssh). I want seamlessly copy and paste between Vims in tmux splits. I tried a bunch of plugins, but none of them worked, thus the question.

grodzik
  • 4,588
  • 19
  • 27
ashim
  • 101
  • and the same question here, where do you get stuck ? what have you tried. Do you want to overwrite y and p ore have 2 new commands (YankToFile, CopyFromFile)? – B.G. Aug 23 '17 at 06:28

1 Answers1

0

Use register +. For yanking use "+y which yanks to register + and for pasting use "+p which copies content from +.

I use the following maps in my vimrc to copy to system clipboard

noremap <leader>y "+y<CR>
noremap <leader>p "+p<CR>
statox
  • 49,782
  • 19
  • 148
  • 225
Aditya Varma
  • 113
  • 4
  • use tmux,tmux buffer to unname register, uname register to tmux buffer

    https://github.com/tracyone/t-vim/blob/master/autoload/te/tmux.vim

    – tracyone Aug 23 '17 at 09:57
  • 1
    @c0de222 Using the + register does not work for copying between vims in different tmux splits, unfortunately. – ashim Aug 23 '17 at 17:20
  • @tracyone Can you please provide more details how to use the script? Somehow it did not worked out for me. I moved tmux.vim to ~/.vim/bundle/tmux.vim and "set runtimepath^=~/.vim/bundle/tmux.vim" . However, regular y and p did not paste between vims in tmux splits. – ashim Aug 23 '17 at 17:30
  • https://github.com/tracyone/t-vim/blob/master/rc/tmux.vim#L23-L24 – tracyone Aug 23 '17 at 23:12
  • Alternatively, add these three mappings to your vimrc: vmap <C-c> :w! ~/.vbuf<CR>, nmap <C-c> :.w! ~/.vbuf<CR>, nmap <C-v> :r ~/.vbuf<CR>. – sente Oct 18 '17 at 09:12