30

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?

2 Answers 2

62

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.

Sign up to request clarification or add additional context in comments.

6 Comments

+1. Out of dozens of tmux SO questions I read, this is the first one that differentiates well between versions when it comes to scrolling with vim keys. Exactly the information I needed (to solve a different problem though). Thanks a lot!
To use this answer first install xclip package. for Debian based apt install xclip
We're still tied down to tmux 1.8 for some reason, so the different config is useful.
tmux config is located in ~/.tmux.conf if you want to run these lines when the server starts
|
17

To supplement the accepted answer, I found the following .tmux.conf lines accomplished most of what I needed:

set-window-option -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.