Joseph O'Shea

Making your command line effective and enjoyable — Part 2: tmux

clitmuxtmux-resurrecttmux-continuum

Why is tmux awesome?

Resources

Outline

Notes on tmux usage

Please read the great crash course guide before getting started. It will explain the basics quite well.

Here is a quick reference of some useful commands and hotkeys.

Sessions

I think of sessions as "workspaces" - I typically have one per project and name them accordingly. If you are using tmux-continuum as specified in the example .tmux.conf (which I strongly recommend - if there is only one part of my config you copy, it is that), your sessions will be saved and restored even after restarting your machine. This is extremely useful since it preserves all your open windows and panes with their working directories and such. This makes context switching between projects far less painless, and makes jumping back into a project after a reboot a breeze as well.

I strongly recommend you use tmux-continuum and name your sessions well so that you can easily return to the appropriate session for whatever you are working on at any given time.

Windows

Windows are great. Think of them like tabs in a typical GUI console, but better. Windows will be saved when you detach from your session (and since you're using tmux-continuum, they are saved until you decide to close them!) which is very useful. There are also several hotkeys for navigating through windows.

Usage Example

My default window setup when working in a local VM is something like this:

While I could just have these windows open in traditional tabs in a GUI console, I like tmux windows better for a few reasons:

Of coure this is just an example of how tmux has improved my workflow, but you should adopt whatever makes you the most productive and comfortable!

Panes

Panes are really awesome. They allow you to split a window into multiple shells. You can see each of the shells running in the panes of your active window and you can quickly switch between panes with hotkeys.

note: this section assumes you're using the example .tmux.conf

Clipboard

Example .tmux.conf

# remap prefix to Control + a (change this to whatever you are most comfortable with!)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
#set -g @plugin 'tmux-plugins/tmux-sensible'

# continuum
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'


# Control arrow to create panes
bind -n C-Down  split-window -v
bind -n C-Up    split-window -v -b
bind -n C-Right split-window -h
bind -n C-Left  split-window -h -b

# Easier window navigation
bind -n C-Tab     next-window
bind -n C-S-Tab   previous-window
bind -n C-S-Left  previous-window
bind -n C-S-Right next-window

# Ctrl + Alt + Left/Right to move windows
bind-key -n C-M-Left swap-window -t -1
bind-key -n C-M-Right swap-window -t +1

# Terminal improvements
set -g mouse on
set-option -g allow-rename off # keep window names as you set them; turn this off to have window name update based on the process running in it

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'