Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tmux change scroll up/down keys

Tags:

vim

vi

tmux

Currently when I want to go into scroll mode I press Ctrl+b and then [. However after entering copy-mode, I must use the up and down keys to scroll up or down. I would prefer to k for up and j for down.

How do I change the scrolling behaviour so that scroll down happens when I press k and scroll up happens when I press j?

like image 443
Mfswiggs Avatar asked Jul 01 '15 07:07

Mfswiggs


People also ask

How do you move up in Tmux?

Scrolling with keys is enabled by default in Tmux. Just press ctrl + b then [ to move around with the arrow keys. Just as with the mouse settings you have to add them to your . tmux.

How do I scroll through Tmux terminal?

Scrolling Up and Down in Tmux If you want to scroll the Tmux terminal, enter the copy mode by pressing the “Ctrl+b” combination and entering “[”. Now, you can use the navigation keys like arrows (up and down) for moving line by line. Left and right arrows can be used for character by character moving.

How do you change panes in Tmux?

Tmux uses the keybinding 'Prefix' followed by 'Ctrl+o' to cycle around the panes. When you use this key-binding for the first time, it moves the pane in one position clockwise.

How do I scroll in Tmate?

The SSH shell session uses a fork of tmux (https://github.com/tmux/tmux) which is a Terminal multiplexor program called tmate (https://tmate.io/) and with it you can open Windows, scroll through history, and more. To quit the history scroll mode, you simply press the letter q.


1 Answers

I use a .tmux.conf file with something similar to the following, which I adapted to your question

# Set tmux to Vi mode
set-window-option -g mode-keys vi
# Scroll up/down with j/k
bind-key -t vi-copy 'j' page-up
bind-key -t vi-copy 'k' page-down

Although this seems unnecessary because in vi mode, the hjkl work as expected, and you scroll up/down with J/K (Shift+J, Shift+K) which work just fine

To make it even more Vim-like I add following:

bind-key -t vi-copy 'v' begin-selection                  
bind-key -t vi-copy 'y' copy-selection

Which works like Vim's visual select and yank

Note: After configuring the file you have to reload it, e.g. with the tmux command :source ~/.tmux.conf

like image 118
bakkal Avatar answered Oct 21 '22 15:10

bakkal