Search code examples
vimvitmux

Tmux change scroll up/down keys


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?


Solution

  • 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-down
    bind-key -t vi-copy 'k' page-up
    

    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