1

I'm testing out using vim with tmux. One thing that I could do with vim with a split window is yank text from one buffer and paste it into the other. This no longer works when I have vim buffers in different panes. Any idea how to get this working?

I'm working on Mac Terminal (El Capitan) over SSH into a Linux box.

UPDATE And it does not look like my version of vim has the +clipboard feature compiled into it.

NOTE This is not a duplicate question as this is specifically about using tmux with vim. I want to be able to issue a yy command like I usually do in one vim pane in tmux and p it into another vim pane in tmux.

muru
  • 24,838
  • 8
  • 82
  • 143
StevieD
  • 1,492
  • 1
  • 16
  • 24
  • 6
    This has nothing to do with tmux, you simply want to be able to yank/paste between two different instances of vim, right? – pfnuesel Apr 21 '16 at 04:03
  • +clipboard is for graphical vim; it won't be relevant for running vim in a terminal. Sounds like you probably either want to copy/paste using the terminal itself, or try having your console session interface with OSX directly. There's probably a way to use pbpaste and pbcopy to do what you want if you set up a key binding; see http://stackoverflow.com/questions/5130968/how-can-i-copy-the-output-of-a-command-directly-into-my-clipboard and http://superuser.com/questions/231130/unable-to-use-pbcopy-while-in-tmux-session/413233#413233 (I'd try myself, but I don't have an OSX box). – ZeroG Apr 21 '16 at 12:54
  • @pfnuesel, yes, I want to do a yy command in one pane and p into another pane. I can't use the system clipboard because my non-gui version of vim does not have the clipboard compiled into it. I've tried many of the various solutions recommended but nothing seems to work. – StevieD Apr 21 '16 at 13:24
  • I wonder if this is the reason why I'm having trouble: https://support.apple.com/en-us/HT201341 – StevieD Apr 21 '16 at 13:37
  • 2
    It's cumbersome, but without access to the system clipboard, I think a shared file is the simplest way. – muru Apr 21 '16 at 15:59
  • 3
    tmux has a "copy mode", but it's a bit awkward to use. It also has the :set-buffer and :paste-buffer commands, as well as some other related commands (see the BUFFERS section in tmux(1)). Not entirely sure how to run this from Vim (maybe something with :bind-key -n yy ...?) It also has the Ms terminfo extension to interface with the clipboard (with :set-clipboard). – Martin Tournoij Apr 21 '16 at 19:04

2 Answers2

2

Use fakeclip.vim. See this answer for details.

1

First off, I'd like to note that the implication that you cannot use the system clipboard from terminal Vim is false. I use it all the time. (This implication isn't in your question, but it is in the comments.) So if I were in your situation, I would simply install a different Vim package that does include the +clipboard feature.

That said, here's a proof of concept which uses a tmux buffer and the system() function to provide (just) the functionality you asked for:

nnoremap <silent> yy yy:call system('tmux set-buffer -b vim ' . shellescape(@"))<CR>
nnoremap <silent> p :let @" = system('tmux show-buffer -b vim')<cr>p$x

These mappings use the standard yy and p commands to perform the actual yank and put, but include system calls to save the contents of the unnamed register in a tmux buffer after yanking and load the buffer contents back into the unnamed register before putting.

N.B. If I were using this in earnest, I would extend this and tidy it up a fair bit (for instance, with these mappings you can now only p things that you have previously yanked with yy: the easiest way around this is use <leader>yy and <leader>p as the triggers), but this shows the basic functionality.

Here's another version which instead uses tmux's send-keys to directly copy over the contents of the unnamed register when you yank, which in some ways is cleaner, and avoids the problem with the p mapping described above:

nnoremap <silent> yy yy:call system('tmux send-keys -t 1 ":let @\" = \"' . shellescape(@")[1:-2] . '\"' . "\r\"")<CR>

Currently this is losing the newline at the end of the yanked line: it could probably be tidied up not to do so.

Rich
  • 31,891
  • 3
  • 72
  • 139