tmux usage - deeper

# Vim keys in copy mode
setw -g mode-keys vi
 
# Enable mouse
set -g mouse on
 
# Enter copy mode with PageUp
bind -n PageUp copy-mode -u

  

If you're a Vim user, absolutely yes, I would recommend:

 

set-option -g mode-keys vi

 

or in ~/.tmux.conf:

 

setw -g mode-keys vi

 

Difference: emacs vs vi

This setting only affects copy mode, command prompts, and some text editing in tmux. It does not change your shell (bash/zsh) behavior.

mode-keys emacs (default)

Navigation resembles Emacs:

ActionKey
Up Ctrl+p
Down Ctrl+n
Left Ctrl+b
Right Ctrl+f
Beginning of line Ctrl+a
End of line Ctrl+e
Exit copy mode q / Esc

For Vim users, these shortcuts often feel unnatural.


mode-keys vi

Navigation resembles Vim:

ActionKey
Up k
Down j
Left h
Right l
Page down Ctrl+f
Page up Ctrl+b
Top g
Bottom G
Search forward /
Search backward ?
Next match n
Previous match N
Exit copy mode q

This makes tmux scrollback feel very similar to reading a file in Vim.


Enable permanently

Edit:

 

vim ~/.tmux.conf

 

Add:

 

setw -g mode-keys vi

 

Reload without restarting tmux:

 

tmux source-file ~/.tmux.conf

 

Verify:

 

tmux show -g mode-keys

 

Output:

 

mode-keys vi

 


Even better Vim setup

Many Vim users also add mouse scrolling and easier copy-mode entry:

 

# Vim keys in copy mode
setw -g mode-keys vi
 
# Enable mouse
set -g mouse on
 
# Enter copy mode with PageUp
bind -n PageUp copy-mode -u

 


Useful vi-mode copy shortcuts

After entering copy mode:

 

Ctrl+b [

 

Common operations:

 

g       Top of history
G       Bottom of history
/       Search forward
?       Search backward
n       Next match
N       Previous match
 
Ctrl+u  Half page up
Ctrl+d  Half page down
 
q       Exit copy mode

 

Visual selection (Vi style)

 

Space   Start selection
Enter   Copy selection
q       Exit

 

Or in newer tmux versions:

 

v       Begin selection
y       Copy selection

 

with these bindings:

 

bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-selection-and-cancel

 

This gives a very Vim-like experience inside tmux. For developers who spend a lot of time in Vim/Neovim + tmux + SSH, mode-keys vi is generally the preferred configuration.

posted on 2026-09-26 20:55  ENGINEER-F  阅读(2)  评论(0)    收藏  举报