I am a Neovim (or Nvim in abbreviation) user. In Nvim, we use
Ctrl-W as prefix for window-related
operations. But in tmux, the default prefix is
Ctrl-B. As a result, when I want to change panes in tmux, I often mistakenly press
Ctrl-W, which is annoying. Why not change tmux prefix to be more vim-like?
Tmux does not create a configuration file under your home by default. You have to create one by yourself. First, we need to create a config file named
.tmux.conf under home directory:
Then, we can edit this file to customize tmux behaviours.
To change prefix, add the following settings to
unbind C-b set-option -g prefix C-w bind-key C-w send-prefix
Split panes like vim
By default, tmux use
<prefix> % to split window vertical and
<prefix> ", which is rather obscure. We can change it to be more vim-like.
# use <prefix> s for horizontal split bind s split-window -v # use <prefix> v for vertical split bind v split-window -h
Then you can use
<prefix> s to for horizontal split and
<ctrl> v for vertical split.
Vim-like pane navigation
In order to use the traditional Vim navigation key
HJKL for switching between different panes, use the following settings:
bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R
Then you can use
<prefix> h/j/k/l to go to pane left/below/above/right.
We can also use alt and arrow keys for pane switching,
bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D
Then you can press
Alt + arrow key to switch panes.
# resize panes more easiyly bind < resize-pane -L 10 bind > resize-pane -R 10 bind - resize-pane -D 10 bind + resize-pane -U 10
To resize pane in the horizontal direction, use
<prefix> < or
<prefix> >. To resize pane in the vertical direction, use
<prefix> + or
How to make the changes take effect?
If you are in a tmux session, just press
<prefix>, then use
:source ~/.tmux.conf command to make the change take effect. If you are in the normal command line, use
tmux source ~/.tmux.conf to refresh tmux configurations.
Note: before changing the tmux prefix key, the old prefix still takes effect. If you want to change the prefix inside a tmux session, you need to use the old prefix.
License CC BY-NC-ND 4.0