---
title: Migrating from GNU Screen to Tmux
teaser: 'Upgrade to Tmux if you''re already using Screen to multiplex your terminal.

  '
tags: cli,devtools,tmux,new bamboo,web
author: Tom Wey
published_on: 2015-02-20
---

_This post was originally published on the New Bamboo blog, before [New Bamboo
joined thoughtbot in London][new-bamboo-thoughtbot]._

---

A while back I took the plunge and moved from using [GNU Screen] to [Tmux] for
all of my terminal multiplexing needs.

I'd been a happy Screen user for quite a few years. I'm also a Vim user and this
combination means I get to spend a lot of time in the terminal. There were a few
reasons I finally decided to make the switch. The biggest one was that here at
New Bamboo I was the sole Screen user surrounded by many enthusiastic Tmux users
(including the author of [Hermes]) and I felt I was missing out on being able to
tap into all this expertise!

Almost as importantly, Tmux's great UTF-8 support means I can include an
adorable panda face in my prompt:

![](https://images.thoughtbot.com/new-bamboo/blog/migrating-from-screen-to-tmux/8BBsyJ9XTCmppycvJnmH_panda_prompt.png)

### Easing the transition

There were a few specific tips and bits of configuration which made the initial
transition from Screen very pain free and allowed me to get up and running
quickly:

#### Starting a new session

I was used to starting or reattaching to a Screen session with:

<kbd>screen -UdR</kbd>

The flags tell screen to use UTF-8 encoding (`U`), detach elsewhere and reattach
here (`d`) and finally to reattach if possible, otherwise start a new session
(`R`).

Tmux requires us to be a little more explicit. To start a new session:

<kbd>tmux new -s \<session name\></kbd>

To reattach to an existing session:

<kbd>tmux attach -t \<session name\></kbd>

That's a little too much typing for my liking, so I alias these two commands to
`tn` and `ta` respectively.

To detach (as in Screen):

```sh
<prefix e.g. C-a> + d
```

Tmux automatically turns on UTF-8 support if it successfully detects a UTF-8
capable terminal, so there's usually no need to specify this explicitly.

#### Remapping prefix to Ctrl-a

By default Tmux commands are prefixed with `Ctrl-b`. In Screen it's `Ctrl-a`,
which has been firmly committed to my muscle memory. Fortunately it's easy to
change this by adding the following to our `tmux.conf`:

```sh
unbind C-b
set -g prefix C-a
```

#### Toggling windows with Ctrl-a + Ctrl-a

Great, now we can move around our windows with `Ctrl-a + n`, `Ctrl-a + p` and
`Ctrl-a + <window-number>` just like in Screen.

One missing piece is the ability to toggle back to your previous window with
`Ctrl-a + Ctrl-a`. This can be achieved by adding the following to our
`tmux.conf`:

```sh
bind-key C-a last-window
```

#### Jump to beginning of line in Bash

In Bash (using the default readline key bindings) `Ctrl-a` moves the cursor to
the beginning of the line. Within Screen this becomes `Ctrl-a + a`. To enable
the same combination within Bash in a Tmux window add the following to your
`tmux.conf`:

```sh
bind a send-prefix
```

#### Vim Copy/Paste under Mac OS X

As a Vim user, I noticed pretty quickly that Vim/OS X clipboard integration
(enabled in my vim config with `set clipboard=unnamed`) didn't work under Tmux.
A quick Google led me to Chris Johnsen's [excellent set of notes and
workarounds][tmux-pasteboard] which provides a [wrapper script][tmux-wrapper]
you can use to start all new Tmux windows. This fixes clipboard integration and
got me back the functionality I was missing.

#### Accessing scrollback history

I was happy to find that paging/searching back through terminal scrollback
history is exactly the same in Tmux as in Screen. To enable copy mode use
`Ctrl-a + [`. From here you can page up and down with `Ctrl-u` and `Ctrl-d`. You
can also search backwards using `?` followed by your pattern. To exit copy mode
use `Ctrl-c`.

### Final thoughts

I've been using Tmux for a while now and I'm really happy with it as part of my
toolchain. There's a great community out there so it's generally straightforward
to find answers to questions and solve any issues. It's also under [active
development][tmux-source] with regular releases which is great news for users.

[GNU Screen]: http://www.gnu.org/software/screen/
[Hermes]: https://github.com/New-Bamboo/Hermes
[new-bamboo-thoughtbot]: https://thoughtbot.com/blog/new-bamboo-joins-thoughtbot-in-london
[tmux-pasteboard]: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
[tmux-source]: http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/
[tmux-wrapper]: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard#the-wrapper-program
[Tmux]: http://tmux.sourceforge.net/
