Reputation: 31266
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?
Upvotes: 25
Views: 31180
Reputation: 11484
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.
Upvotes: 54
Reputation: 31266
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
Upvotes: 15