Join my Bash scripting course on Udemy πŸ‘€

Remapping the split window keys in tmux

October 10, 2020  ‐ 2Β min read

In tmux you can split your panes horizontally with <prefix> " and vertically with <prefix> % by default. I quite often forgot these keybindings so wanted to remap them to something more meaningful.

I decided on <prefix> - to split vertically and on <prefix> \ to split horizontally. I would prefer | over \, but it requires me to press an extra key.

This seems counterintuitive, because well, a hyphen(-) is horizontal and a backslash(\) is vertical. But if you see how tmux splits windows it makes more sense.

A tmux window that is split horizontally looks as follows. It is split from left to right, with a pane border in the middle. Hence the backslash.

+–––––––––+–––––––––+
|         |         |
|         |         |
|         |         |
|         |         |
|         |         |
+–––––––––+–––––––––+

You can add the bindings for <prefix> - and <prefix> \ by putting the following in your ~/.tmux.conf file. I unbind the default bindings as well, so I can reuse them for something else if I need to.

# ~/.tmux.conf

# Split panes with \ and -
bind \\ split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

Take notice that you need to escape the backslash, that's where the bind \\ comes from.

In most cases I like the new split to be in the directory as I am currently in. So I added the option -c "#{pane_current_path}" to do so. If you don't prefer this you're set with the following configuration.

# ~/.tmux.conf

# Split panes with \ and -
bind \\ split-window -h
bind - split-window -v
unbind '"'
unbind %

Learn more

A great resource for learning more about tmux are its man pages. You can read them online here or from the command-line using the following command:

$ man tmux

Or take a look at this book: