Vim-like Settings for Tmux
I am a Neovim (or Nvim in abbreviation) user. In Nvim, we
Ctrl-W as prefix for window-related operations. However, the default
Ctrl-B in Tmux. As a result, I often mistakenly press
trying to change panes inside Tmux, 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 yourself. First, we need to create a config file named
.tmux.conf under home directory:
Then, we 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> % and
<prefix> " to split window vertically
and horizontally respectively, which is rather obscure. We can change it to be
# use <prefix> s for horizontal split bind s split-window -v # use <prefix> v for vertical split bind v split-window -h
Then we can use
<prefix> s and
<prefix> v to create horizontal and vertical
Vim-like pane navigation
In order to use the traditional Vim navigation key
HJKL to switch 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 we can use
<prefix> h/j/k/l to go to pane left/below/above/right.
We can also use Altand 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 we can press
Alt followed by arrow key to switch panes.
# resize panes more easily 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
To resize pane in the vertical direction, use
<prefix> + or
How to reload tmux config?
If you are in a tmux session, just press
<prefix>, then use command
:source ~/.tmux.conf to refresh the Tmux session. If you are outside of a Tmux session,
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