Last year (actually circa January/2014), I found myself struggling with four terminal emulators open, and I knew it was time to work on improving my workflow. I had already heard about those terminal multiplexer thingies, and they seemed to be what I needed. After some research, I decided to stick with tmux, and it’s freaking awesome.

Below is a picture of tmux running on the Gnome terminal. It features the Base16 Solarized color theme, my custom tmux colors and the Ubuntu Mono derivative Powerline font.

My tmux settings

The thing is, there are lots and lots of tutorials on tmux, but I could not find a canonical reference to it - until I discovered this book from the The Pragmatic Programmers series, tmux: Productive Mouse-Free Development.

The book is nothing more than a complete tmux reference - and a very didactic one. The author starts showing you how to use the basic tmux features and how to set it up, and as the book progresses he shows you more complex features, all in a very straightforward manner. Really cool, really simple, the way I like my books. ;)

My personal notes

[PREFIX] is CTRL+B or CTRL+A, depending on the settings (mine is CTRL+A).

Chapter 1 - Learning the basics

  • Starting tmux: $ tmux
  • Closing a session: $ exit
  • Named sessions
    • They are useful because they can be organized and put on hold: $ tmux new -s <name>
  • Detaching and attaching sessions
    • Programs or processes can be started up inside tmux, and then be left running on the background.
    • Detach: PREFIX + D
    • List existing sessions: $ tmux ls
    • Attach to a session (single session running): $ tmux a
    • Attach to a session (many sessions running): $ tmux a -t <name>
    • Kill a session: $ tmux kill-session -t <name>
  • Working with windows
    • Create a window: PREFIX + C
    • Rename current window: PREFIX + ,
    • Move between windows
      • Next window: PREFIX + N
      • Previous window: PREFIX + P
      • Find by name: PREFIX + F
      • List menu: PREFIX + W
      • Kill window:PREFIX + &
  • Working with panes
    • Split vertically: PREFIX + % or PREFIX + \
    • Split horizontally: PREFIX + " or PREFIX + -
    • Cycle through panes: PREFIX + O
    • Move around panes PREFIX + [↑,←,↓,→]
    • Close a pane PREFIX + X
  • Command mode: PREFIX + :
  • Show tmux bindings: PREFIX + ?
  • Show pane numbers: PREFIX + Q

Chapter 2 - Configuring tmux

  • tmux settings are found in the ~/.tmux.conf file
  • Config changes are applied when tmux is restarted by entering PREFIX + R or by typing source-file ~/.tmux.conf
  • Keys can be bind to a series of commands by using \;: bind R source-file ~/.tmux.conf \; display "Reloaded!"
  • Status bar items
#H       hostname
#h       hostname without domain
#F       current window flag
#L       current window index
#P       current pane index
#S       current session name
#W       current window name
##       literal #
#[ATTR]  color or attribute change

Chapter 3 - Scripting customized tmux environments

  • Custom scripts can be built to automate certain editor tasks.
  • tmuxinator can be used to write and manage different tmux configurations.

Chapter 4 - Working with text and bugffers

  • Scrolling with copy mode
    • Enter copy mode: PREFIX + [
    • Navigate using the arrow key, PG Up/Down and Vi keys
    • Exit copy mode: ENTER
    • Jump to next word: w
    • Jump to previous word: b
    • Jump to top: g
    • Jump to bottom: G
    • Up one page: CTRL + b
    • Down one page: CTRL + f
  • Searching
    • Search downward: /
    • Search upward: ?
    • Jump to the next occurrence: n
    • Jump to the previous occurrence: N
  • Copying and pasting text
    • Move the cursor to where you want to start selecting the text, press SPACE and move the cursor to the end of the text. Press ENTER to copy it to the buffer.
    • Paste the captured text (on copy mode): PREFIX + ]
    • List all paste buffers: PREFIX + =

Chapter 6 - Workflows

  • Panes and windows
    • Turn a pane into a window: PREFIX + !
  • Managing sessions
    • Go to next session: PREFIX + )
    • Go to previous session: PREFIX + (