---
title: 'tmux Copy & Paste on OS X: A Better Future'
teaser:
tags: tmux
author: Chris Toomey
published_on: 2013-07-19
---

[tmux recently updated to version 1.8](http://sourceforge.net/projects/tmux/files/tmux/tmux-1.8/), and with the update came a new command that greatly simplifies integrating with the OS X clipboard.

![tmux Copy](//images.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future/tmux.gif)

With prior versions of tmux, there wasn’t a straightforward method for getting text copied in tmux to the OS X clipboard. In [How to Copy and Paste with tmux on Mac OS X](https://thoughtbot.com/blog/post/19398560514/how-to-copy-and-paste-with-tmux-on-mac-os-x) we shared the best solution available at the time, but it required a handful of other configurations working together to make copy and paste work.

## What Changed

The key update that comes with tmux version 1.8 is a new command called `copy-pipe`. This command allows you bind a key to both copy the selected text to the tmux paste buffer and pipe the selected text into an arbitrary shell command.

## Setup

In order to make use of this new command, you will still need to install the `reattach-to-user-namespace` wrapper, which will connect tmux to the OS X clipboard service. Thankfully, [homebrew](http://brew.sh/) makes this easy:

    brew install reattach-to-user-namespace

From there you can add the following lines to your `.tmux.conf` file and you will be able to copy and paste:

    # Use vim keybindings in copy mode
    setw -g mode-keys vi

    # Setup 'v' to begin selection as in Vim
    bind-key -t vi-copy v begin-selection
    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"

Note: these settings will cause tmux to use Vim-like key bindings when in copy-mode. You can see the list of key-bindings this provides by running the following command in your shell:

    tmux list-keys -t vi-copy

## Usage

1. `<prefix> [` to start “copy-mode” (Not sure what `<prefix>` is? [This post](https://thoughtbot.com/blog/post/2166174647/love-hate-tmux) can help)
1. Move to the text you want to copy using Vim-like key bindings, i.e., `k` to move up a line, `/` to search, etc.
1. `v` to start selection
1. Move to end of text with Vim key-bindings. The selection will be highlighted
1. `y` to copy the highlighted/selected text

The selected text is now in your clipboard, and your day is that much better for it.
