Somewhere between upgrades in the last couple of days, tmux
changed how it
handles split-window
: ‘size’ no longer has a separate option for percentage
(-p
) but -l
can do by-percentage if you include ‘%’ in the arg value (IIRC,
-l
was for size-by-number-of-lines).
This gave me enough of a reason to talk a bit about tmux
.
‘Prefix-key’ (^B
)
You can remap the prefix key to something more comfortable (or familiar) in your
tmux.conf
.
I use C-a
(like GNU screen
), which is less of a stretch of the hand:
unbind-key C-b
set-option -g prefix C-a
If you do this, you may have to also configure a way to send those key-codes to
whatever you’re running in tmux
, which you can do with send-prefix
.
I actually have it set to something other than C-a
(for another reason), so I
use plain a
:
unbind-key a
bind-key a send-prefix
Quick Window Switching
I set a
to send-prefix
so that I can set C-a
to last-window
:
bind-key C-a last-window
This means I can double-tap the prefix-key to quickly switch back-and-forth between windows.
Slightly Different New Window
Creating a new window is prefix c
, but each new-window
starts in the
current session’s ‘path’ (which can be queried with tmux list-sessions -F '#{session_path}'
)
If you would prefer that the default would be to have new windows open in the working directory of the current window (well, pane), you can use a similar action:
unbind-key c
bind-key c new-window -c "#{pane_current_path}"
Heavy-handed Shortcuts
One thing I like to do is map the same action for a key additionally to include the control modifier so that I don’t have to worry about lifting my finger off the control key.
For things like detach-client
(prefix d
) and new-window
(prefix c
), this
is pretty straightforward:
unbind-key C-d
unbind-key C-c
bind-key C-d detach-client
bind-key C-c new-window -c "#{pane_current_path}"
For selecting between sessions (prefix s
), it’s a little bit more different,
since choose-session
isn’t a thing.
Instead, there’s another command to use: choose-tree
.
unbind-key C-s
bind-key C-s choose-tree -Zs
This is the same way that tmux
does it with prefix s
, so look up
choose-tree
in the tmux
manual to figure out what the flags really do.
Pane Pain
The keys for splitting windows don’t make a lot of sense to me, but I suppose there’s some reason for choosing them.
One thing I find kind of annoying is navigating between panes is tiresome
thanks to having to start each movement with prefix
.
My personal solution is to map pane management keys to bare Alt-key combos, without having to prefix them. This is due partly to almost none of my terminal programs requiring alt-key combos.
To wit, splitting windows is mapped to keys more symbolic: -
for vertical
split (cutting across), and \
for horizontal split (cutting down, but also
for my en_us
keyboard, |
is the same key as \
minus the shift modifier).
bind-key -n M-- split-window -vc "#{pane_current_path}"
bind-key -n M-\\ split-window -hc "#{pane_current_path}"
I favor pane cycling over directional navigating, so rather than mapping
hjkl
I just map tab
to cycle up/down:
bind-key -n M-Tab select-pane -t :.+
bind-key -n M-BTab select-pane -t :.-
The last part is just a simple way to swap the current pane with the first pane:
bind-key n M-Enter swap-pane -s :. -t :.0 -d
All Together
All of this pretty much covers the bulk of my tmux
set up. I avoid plug-ins
and themes, and the rest of my configuration covers most of that.
As well, I greatly simplify session management with a few terminal scripts/functions, so there’s none of that as well.
The whole keybinding configuration:
# change prefix
unbind-key C-b
set-option -g prefix C-a
# send prefix to program
unbind-key a
bind-key a send-prefix
# window jumping
unbind-key C-a
bind-key C-a last-window
# new windows
unbind-key c
unbind-key C-c
bind-key c new-window -c "#{pane_current_path}"
bind-key C-c new-window -c "#{pane_current_path}"
# extra variations
unbind-key C-s
unbind-key C-d
bind-key C-s choose-tree -Zs
bind-key C-d detach-client
# window splitting
unbind-key '"'
unbind-key %
bind-key -n M-- split-window -vc "#{pane_current_path}"
bind-key -n M-\\ split-window -hc "#{pane_current_path}"
# window cyling, move
bind-key -n M-Tab select-pane -t :.+
bind-key -n M-BTab select-pane -t :.-
bind-key -n M-Enter swap-pane -s :. -t :.0 -d