I’ve been using tmux since RHEL stopped shipping screen by default.  We now use Oracle Linux at work, not RHEL, and perhaps Oracle Linux ships screen, but I’m unlikely to switch back now.

I blundered upon a tmux book at the Toronto Public Library today.  It’s a little book, and most of what is interesting looking to me, is in the first couple chapters.  Here are some notes.

tmux sessions.

I normally want just one tmux session per machine, but tmux does have the capability of creating named sessions. I knew this, but hadn’t used it, and it’s spelled out nicely in the book.  Here are two bash aliases to exploit that feature:

alias tplay='tmux new -s play'
alias twork='tmux new -s work'

Here are two such sessions in action:

Notice the little [work] and [play] indicators in the bottom left corner of each screen session.  Nice!

Of course, I created a couple aliases to attach to my named sessions:

alias atplay='tmux at -t play'
alias atwork='tmux at -t work'

tmux window switching “menu”

The only thing screen feature that I miss is the menu of windows for the session, but I’ve gotten used to that limitation.

However, because tmux shows the active sessions at the bottom, you can use that as an built in session switching mechanism.

Do this with [Prefix] N, where N is the window number.  [Prefix] is the notation from the book that has the control sequence used for shortcuts.  For me, because I have this in my .tmux.conf

unbind C-b
set -g prefix ^N
bind n send-prefix

For me, [Prefix] is control-n (I don’t remember why I had ‘set -g’ and bind, which looks redundant to me.) So, I can do window switching with

control-n 1
control-n 2

Most of the time I use my F5, and F8 commmand key mappings to do window switching

bind-key -T root F5 select-window -p
bind-key -T root F6 select-window -l
bind-key -T root F8 select-window -n
bind-key -T root F9 new-window

but this ‘[Prefix] N’ gives me another way to do window switching.

However, what do you know, there is an equivalent to the old screen window selection mechanism, as I’ve just learned from the book:

[Prefix] w

This window switcher is actually really cool. It shows a preview of the window to be selected, and even shows the windows in both named sessions, so not only is it a window switcher, but also a session switcher!

Panes

I’d seen that tmux has support for window splitting, but have never used it.

Here are the commands, for new vertical split, new horizontal split, pane cycle, and pane navigate:

[Prefix] %

[Prefix] ”

[Prefix] o

[Prefix] Up-Arrow,Down-Arrow,Left-Arrow,Right-Arrow

Looks like the pane splitting is specific to the active window, so if you do a split pane, and have run a rename-window command, for example, using something like:

alias tre='tmux rename-window'
function tnd
{ 
    tmux rename-window `pwd | sed 's,.*/,,'`
}

then the split pane only shows up in that named window, like so:

Some random tricks

Detach: [Prefix] d

(I use command line ‘tmux det’)

Switch between horizontal and vertical panes: [Prefix] space

Create new window: [Prefix] c

(I use my F9 bind-key mapping)

 

Pane mapping bind-keys for adjusting window size:

tmux bind -r H resize-pane -L 5
tmux bind -r J resize-pane -D 5
tmux bind -r K resize-pane -U 5
tmux bind -r L resize-pane -R 5

(can also be put into the .tmux.conf without the leading tmux)

This allows you to resize panes. For example, perhaps you want to tail the output of something long running, or run top, or something else, but have the rest of the upper pane in action, something like: