So if I am in Tmux and a bunch of output came to the terminal, I can scroll through it by pressing:
ctrl-b [
Now, I have to pick my hands up and go to the arrow keys to scroll up.
How do I map the vim keys in scroll mode?
Update in 2025: Tmux 3 version:
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi V send -X select-line
# Mac
set -s copy-command 'pbcopy'
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'pbcopy'
# Linux
set -s copy-command 'xclip -in -selection clipboard'
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
The previous method broke for me when using tmux 3.4 when I upgraded from MacOS 14 Sonoma to MacOS 15 Sequoia.
Update in 2020: I don't think anyone should be using any version of tmux below 2, so the concise configs for modern tmux is just
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi V send -X select-line
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
Previous answer
Unsure which tmux you have. This works for both 1.8 and 2.6, which are the two I'm forced to use.
run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-)"
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' \
"setw -g mode-keys vi; \
bind-key Escape copy-mode; \
bind-key -t vi-copy v begin-selection; \
bind-key -t vi-copy V select-line; \
bind-key -t vi-copy y copy-pipe 'xclip -in -selection clipboard'"
if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.4" | bc)" = 1 ]' \
"set-window-option -g mode-keys vi; \
bind-key -T copy-mode-vi v send -X begin-selection; \
bind-key -T copy-mode-vi V send -X select-line; \
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'"
The relevant section here for hjkl is just setw -g mode-keys vi
for 1.8 and set-window-option -g mode-keys vi
for 2.6 (these might even be aliases and work in both versions, not sure). That being said, the v
and V
mappings with xclip
are definitely useful.