Fix Vim + Tmux yank/paste on unnamed register

Jason picture Jason · Jul 10, 2012 · Viewed 19.4k times · Source

While using vim inside a tmux session I cannot yank or paste to the unnamed register. Going to a named register works fine, but unnamed never works.

Error is:

E353: Nothing in register *

Without tmux, vim works fine using my current settings. How do I fix it so I can use y then p without errors and without specifying the register?

Answer

Chris Johnsen picture Chris Johnsen · Jul 10, 2012

From the error message (Nothing in register *), it appears that when you do a plain? p, your instance of Vim is using the * register instead of the unnamed register*. This is probably because your clipboard option includes the value unnamed. When configured this way, Vim will use the * register instead of the unnamed register for yank, delete, change, and put operations by default (i.e. unless you specify another register with a " prefix; e.g. "ap to put from the a register).

*The unnamed register is actually named " (double quote). It is only “unnamed” in the sense that you do not have to name it to use it (it is the default). I.e. you do not have to say ""p to put from the unnamed register, just p.

The default value of clipboard does not contain unnamed, so it is probably coming from some bit of your configuration (or a plugin). The command :verbose set clipboard? will show you the script that set the current value. If this is being done in your configuration file, then you might want to not do it when you are running under tmux. E.g:

if $TMUX == ''
    set clipboard+=unnamed
endif

Alternatively, there may be some way to let instances of Vim-inside-tmux access the GUI selection/clipboard (thus work with the * register and/or unnamed in clipboard). If you are running Mac OS X, you may want to look at my workaround wrapper that re-enables clipboard access for processes running inside a tmux session. If you are using some other OS or GUI, then you will need to find out how Vim would normally talk to the GUI and why it is not working (e.g. wrong DISPLAY value under X11, possibly due to attaching to an old session that is running a shell that has an out-of-date value).