title = "Tmux and Vim: Copy and Paste on macOS Sierra"
tags = ["vim", "tmux", "terminal", "macos"]
description = "As a developer, more than anything, you copy and paste things. Making copy and paste work in properly with Vim and Tmux is, unfortunately, not trivial."
+++
As a developer, more than anything, you copy and paste things. Making copy and paste work in properly with Vim and Tmux is, unfortunately, not trivial.
There's a lot of information to be found on the internet about setting up copy and paste with Tmux. There's also
lots of information on how to setup Vim. But then you run Vim 8. On macOS Sierra. And things break down
quickly.
This short guide helps you setup Tmux and Vim on macOS Sierra for proper copy pasting glory!
## Dependencies
First, you'll have to install _one_ dependency. I also recommend you install the latest and greatest
Vim instead of using the (old) version bundled with macOS, and of course, tmux.
``` shell
brew install reattach-to-user-namespace
brew install vim tmux
```
## Configure Tmux
Tmux is a weird beast. Copy and pasting can be done in different ways, but I prefer the Vim style navigation.
``` text
# Configure your default shell, Zsh in my case.
set -g default-shell $SHELL
# Override the default command to use `reattach-to-user-namespace` for everything.
set -g default-command "reattach-to-user-namespace -l ${SHELL}"
# Remap prefix to ctrl-a (or caps-a for my mac)
set -g prefix C-a
# Vim style navigation in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection, just like Vim
bind-key -t vi-copy v begin-selection
# Setup 'y' to yank (copy), just like Vim
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
Here are links to my [`~/.vimrc`](https://git.devroom.io/ariejan/dotfiles/blob/e54317082b2a72363dad9aa6bb38310bfe8a6cc8/vim/.vimrc) and [`~/.tmux.conf`](https://git.devroom.io/ariejan/dotfiles/blob/e54317082b2a72363dad9aa6bb38310bfe8a6cc8/tmux/.tmux.conf) for your perusal.