Skip to main content

More tmux Shortcuts, and How to Add Your Own

You have been living in the setup from A Brutally Simple tmux Intro for a while, and the survival kit has stopped feeling like enough. Good. Here are the keys worth learning next, and then the part that actually matters: making your own.

Keys you already have

None of these need a config change. They ship with tmux.

ActionKeys
Zoom a pane to fill the window (and back)Ctrl-a then z
Swap this pane with the one before itCtrl-a then {
Swap this pane with the one after itCtrl-a then }
Scroll back through outputCtrl-a then [
Resize the current paneCtrl-a then Alt-arrow
Show pane numbersCtrl-a then q
Cycle through pane layoutsCtrl-a then Space
List every key, with descriptionsCtrl-a then ?

Zoom is the one you will use most. Two panes are useful right up until you need to read a stack trace, and Ctrl-a z gives you the whole window without disturbing the layout. Press it again to go back.

Swapping panes is not the same as moving between them. Ctrl-a { does not move your cursor to another pane. It picks up the pane you are in and trades places with its neighbour. You stay in the same shell the whole time; the pane moves around you. It is how you fix a layout where the thing you care about ended up in the wrong corner.

Scrolling back is Ctrl-a [, which drops you into copy mode. Arrow keys and Page Up move around, and q leaves. It feels odd the first few times, because your terminal's own scrollbar stops being the thing that scrolls.

Ctrl-a ? is the one to remember when you forget the others. It lists every binding with a description of what it does, which is a better habit than searching the internet for a cheat sheet that may not match your config.

Your first binding

Resizing with Ctrl-a then Alt-arrow works, but it is a lot of fingers for something you do constantly. This is better:

bind -n -N "Resize the pane up by 2" M-k resize-pane -U 2
bind -n -N "Resize the pane down by 2" M-j resize-pane -D 2
bind -n -N "Resize the pane left by 2" M-h resize-pane -L 2
bind -n -N "Resize the pane right by 2" M-l resize-pane -R 2

Add those to the bottom of ~/.tmux.conf, above the run line that loads TPM. Then reload with Ctrl-a then R, and hold Alt while tapping h, j, k, or l.

Four pieces are doing the work:

  • bind attaches a key to a command.
  • -n means no prefix. You press Alt-k on its own, without Ctrl-a first. That is the whole point: resizing is fiddly enough without a prefix in front of it.
  • -N "..." is a description. This is the part people skip, and it is why Ctrl-a ? is useful: your own bindings show up there, described in your own words, instead of appearing as an unexplained key.
  • resize-pane -U 2 is the command, moving the edge two rows at a time.

Dropping the prefix is a real trade. tmux grabs a no-prefix key before anything else sees it, so once Alt-k resizes a pane, your text editor and your shell never receive Alt-k again. tmux ate it. Pick combinations the programs you run inside tmux do not already use.

A key tmux does not give you

Reordering your windows has no default key at all. Add one:

bind -N "Swap this window left" S-Left swap-window -t :-1
bind -N "Swap this window right" S-Right swap-window -t :+1

Now Ctrl-a then Shift-Left moves the current window one place left.

No -n here. A prefixed key costs nothing: Shift-Left still belongs to your editor, and only swaps windows in the moment after Ctrl-a. Save bare keys for what you do constantly, like resizing.

Adding a plugin

The intro installed three plugins for you. Adding a fourth is two steps.

Put the plugin in ~/.tmux.conf, with the other @plugin lines and above the run line at the bottom:

set -g @plugin 'tmux-plugins/tmux-yank'

Then, inside tmux, press Ctrl-a followed by a capital I (for install). TPM clones the plugin and reloads. That is the plugin manager the intro quietly set up for you, and this is the moment you actually need it.

Ctrl-a then U updates your plugins, and Ctrl-a then Alt-u removes ones you have deleted from the config.

If you rebind, tell the palette

The command palette shows a keyboard shortcut next to most commands because the starter setup wrote it a map of which key does what, at ~/.config/tmux-palette/shortcuts.json. It is a plain list of command names and labels:

{
"Zoom / Unzoom": "C-a z",
"Swap Pane Up": "C-a {"
}

tmux cannot tell the palette what your keys are, so if you rebind something on that list, edit the label to match. Bindings the palette does not list (like the resize keys above) need no entry at all.

Where to go next

You now have the two things that matter: enough keys to work, and the ability to change any of them. Everything after this is preference.

When you want to try a config change without risking the setup you rely on, Run a Second tmux Server shows how to run an experiment beside your real sessions instead of on top of them.