Example: copy in one tmux pane (via vim), then switch to another pane (running another vim instance) and paste using the vim paste command. I know this can be done via tmux (using prefix+]) but it would be really handy if I can copy and paste using vim bindings since i'm just switching between different panes running vim.
Any ideas?
I've been used this handy binding for several years :)
Although I agree that it's better to just use one vim instance, you can do this with tmux alone. It has a built in copy-mode. My tmux.conf is set up like:
So you can use
prefix-<C-y>
to activate copy mode,/search term
as an example to go where you want,v
to visually select,y
to yank into tmux. Then go to other vim session and get into insert mode. Useprefix-p
to paste what's in the tmux paste buffer. There are also ways to copy tmux's paste buffer to your system clipboard.solution on Fedora24
you need to use vimx instead of vim
put in your .bashrc or .zshrc
and then you can easily copy between vims/tmux panels
vimx is part of vim-enhanced-2:7.4.1868-1.fc24.x86_64 you most likely have installed
I'm currently stuck with a laptop running Windows at work, but I do all my development on a server running Linux, so I end up working in a tmux session over PuTTY all day.
I wanted to copy text between vim instances running in different windows in my tmux session. I tried using the
*
register to copy to the system clipboard, but since I'm connected through PuTTY I don't have an X session, so there is no system clipboard, even if I launch gVim instead of vim. (I might have been able to use x-forwarding or something to fix this, but I didn't want to install an x-server on windows.)I thought that there should be a way to use the tmux copy/paste buffer from vim in place of the system keyboard, and sure enough someone has written a plugin for that.
Installing fakeclip adds a new register,
&
, which maps to tmux's paste buffer. Since all my vim instances are within the same tmux session, this makes it super simple to yank/put text between them.The plugin documentation says that fakeclip should also work with gnu screen, but I haven't personally tested that.
tl;dr
Install the fakeclip plugin, and then you can use "&y to yank into tmux's buffer, and "&p to put from tmux's buffer.
Sorry, I'm trying to convince you to use vim built-in features.
To make the
copy/paste
easy, you can open files in another Tabpages:Use gt or gT to switch Tabpages.
Or split the window to edit another file:
Use Ctrl-ww to switch Windows.
To split the window vertically, please use
:vsp file
Update:
This is my
.tmux.conf
file:I only use them when I need to copy terminal output.
You can copy the content to clipboard using vim bindings, then switch to the pane and paste it. The following key-bindings might be handy.
The
"+
register is used to access system's clipborad in Vim.Some useful tips:
1. You can press
v
orV
orctrl-v
to enter visual mode, then select the content you want to yank, and pressty
to copy it to your clipboard.2.
ty
can be combined with other motions. For instance,tyaw
can be used to copy a word under the cursor to the clipboard.tyib
copy the content inside parentheses.tyi"
copy the text inside double quotation, etc...See also How to make vim paste from (and copy to) system's clipboard? for further explanation.