42

Yesterday, I upgraded to MacOS Sierra and it broke my clipboard functionality in my tmux + neovim setup.

Here is the behavior:

  • I can use the standard ctrl+c, ctrl+p to copy/paste between system <-> vim
  • I can yank/paste between two VIM instances when NOT in a tmux session
  • I cannot yank/paste between two VIM instances when in a tmux session

Whenever I use the clipboard in vim within a tmux session, I get the following vim error:

clipboard: error:

My .vimrc is huge, but here's what I think might be relevant:

set clipboard=unnamed

In my .tmux.conf (also truncated for brevity):

set -g prefix `                                   # use tilde key as prefix
bind ` send-key `                                 # insert tilde by pressing twice

set -g history-limit 100000                       # set buffer size
set -s escape-time 0                              # fix escape key in vim
set -g allow-rename off                           # keep window names static
set -g default-terminal "screen-256color"         # set the TERM to 256 colors
set -g base-index 1                               # start window count at 1
set -g pane-base-index 1                          # start pane count at 1
set -g default-shell $SHELL                       # use zsh as shell

EDIT: This appears to be related to the bug reported here:

https://github.com/tmux/tmux/issues/543

https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/issues/53

doremi
  • 14,921
  • 30
  • 93
  • 148
  • Neovim or Vim ? – romainl Sep 22 '16 at 18:30
  • @romainl Both, so long as they are running in a tmux session. See the repo mentioned in the 2nd issue link. Appears to be a recurring regression introduced with each new MacOS release. – doremi Sep 22 '16 at 22:34

3 Answers3

57

This seem to be a regression on macOS Sierra. A solution that worked for me has been mentioned by Josh McGinnis https://github.com/tmux/tmux/issues/543:

brew install reattach-to-user-namespace

Ensure the following is set in .tmux.conf:

set -g default-shell $SHELL 
set -g default-command "reattach-to-user-namespace -l ${SHELL}"

In .vimrc or ~/.config/nvim/init.vim (for Neovim):

set clipboard=unnamed

Now all is well and I can copy/paste between system <-> vim sessions using vim keybindings and/or system ctrl+c / ctrl+p.

iltempo
  • 15,718
  • 8
  • 61
  • 72
  • Thank you for this! I held off upgrading for a while for little things like this that may occur. Well, Apple annoyed me for the last time and I upgraded... DOH! – eduncan911 Oct 17 '16 at 14:14
  • 2
    Thanks for this, worked for me. I'm using the "*" register for copying to the clipboard, so I skipped the `set clipboard=unnamed` line. – equivalentideas Oct 20 '16 at 23:13
  • 1
    This work. However, every new tmux pane that is opened is named `reattach-to-user-namespace`. Is this expected? – Christian Fazzini Nov 01 '16 at 16:05
  • 5
    @ChristianFazzini I personally changed this fix a bit to avoid that issue. In my `~/.bashrc` (I use bash), I added `alias nvim='reattach-to-user-namespace -l nvim'`. That way, I'm only calling reattach-to-user-namespace when needed, since I don't copy and paste anywhere else in bash. – take Nov 04 '16 at 19:27
  • `set clipboard=unnamed` worked for me! Thanks! (I'm not even using tmux) – Tibor Vass Mar 08 '17 at 00:49
  • Remember to restart tmux server `tmux kill-server` after reloading `.tmux.conf` configuration. – Egel Mar 29 '17 at 10:31
  • Make sure you're using the Homebrew vim and not the system vim. `which vim` should print `/usr/local/bin/vim`, and `vim --version` should show that the `+clipboard` option is active. Installing Homebrew vim with the `--with-override-system-vi` option should set it up properly. – Christian Long Jan 08 '18 at 16:20
9

Upgrading brew + vim + tmux fixed this for me:

brew update
brew upgrade vim
brew upgrade tmux

Notes:

  • I am not using Neovim but hopefully this will help anyway
  • This may take a while depending on how slow your machine is
  • When I did this brew upgraded ruby for me and it complained that it wouldn't overwrite the existing symlinks so I had to manually run: brew link --overwrite ruby
  • Tmux complained about the following setting after the upgrade. I just commented it out: # set-option -g status-utf8 on
  • I had a warning about needing the new xcode tools so I ran the following and accepted the GUI prompts: xcode-select --install (In hindsight this may mess up my react-native install :/. Buyer beware)
  • When first running brew update brew complained it didn't have write access to /usr/local so I made myself the owner of /usr/local NON-RECURSIVE. After the update brew told me I could change the owner back to root:wheel.
Realistic
  • 1,038
  • 1
  • 10
  • 20
  • It's also worth noting that you need to restart the tmux server with the following command:`tmux kill server` – James Hamilton Dec 08 '16 at 09:32
  • for tmux and Iterm2 I needed to get a test release for this to work (go to iterm2 preferences | general and select `prompt for test releases` in the services section. – diabolist Aug 24 '17 at 15:56
2

I saw the same upon upgrading to Sierra. In my case it stemmed from having the YankRing plugin installed.

Adding the following to my .vimrc fixed it for me:

"-------------------------------------------------------------
" Fix for YankRing bug
"-------------------------------------------------------------
let g:yankring_clipboard_monitor=0
jmromer
  • 2,212
  • 1
  • 12
  • 24