razzi.abuissa.net

Razzi's guide to tmux

tmux is a terminal window manager, powerful but not always user friendly.

installation

$ sudo apt install tmux

Launch with tmux.

Exit with exit or control+d on an empty line, and you’ll be back to the shell where you launched tmux.

configuration

The default key binding is control+b, which is the same keybinding for moving the cursor back a character, so let’s remap it.

I recommend control+space instead. I don’t know of anything that uses this, and space is the easiest key to press anyways.

tmux config goes in ~/.tmux.conf. Uh oh, another bespoke configuration language incoming…

$ cat >> ~/.tmux.conf
set -g prefix ^Space

Honestly that’s all you really need.

From there you can use:

One more keybinding is worth having: prefix space to go the previous tab. I also bind prefix control+space since sometimes I haven’t let go of the control key.

bind Space last-window
bind ^Space last-window

You can add these to your tmux.conf and relaunch tmux or activate it manually with tmux source-file ~/.tmux.conf, or you can enter commands using tmux’s command mode.

To get the command mode prompt, the keybinding is prefix+:, so control+space shift+;.

Enter your command and hit enter, and it’ll be applied. That’s all the tmux config file is doing, executing each line as a tmux command.

keyboard shortcut to reload tmux config

One useful keybinding is reloading the ~/.tmux.conf into your current tmux session, so you can edit ~/.tmux.conf and reload it without having to restart tmux.

I put this under prefix r. Since I split this up onto multiple lines, I have to escape the newline with \, and since it takes multiple commands (I first source the config, then display a message), I put a \; between the commands.

bind r \
  source-file ~/.tmux.conf \; \
  display "Reloaded ~/.tmux.conf"

more intuitive window moving

Add these to your ~/.tmux.conf for vim-style hjkl pane movement.

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

source code

https://github.com/tmux/tmux

depends on