1

The following setting in .tmux.conf breaks arrow keys in terminal in tmux:

set-window-option -g xterm-keys on

When I disable this setting, then arrow keys work as expected in terminal but then they don't work in Vim.

With this setting, the arrow keys move the cursor word wise as option+arrow keys.

The problem occurs both inside Terminal and iterm2.

2 Answers 2

1

I just encountered this same error and fixed it by disabling xterm-keys in my tmux.conf:

setw -g xterm-keys off

I then added the following lines to my .vimrc based on this answer to enable the arrow keys to work correctly inside tmux.

" Needed for tmux and vim to play nice
nnoremap ^[[A <Up>
nnoremap ^[[B <Down>
nnoremap ^[[D <Left>
nnoremap ^[[C <Right>

I added the "^[[A" characters by using Vim's verbatim mode, i.e. pressing Ctrl-v and then the correspodning arrow key.

Finally, I set my tmux terminal to screen256-color using the following line (also in my tmux.conf):

set-option -g default-terminal "screen-256color" 
1
  • Cannot say that this worked, I had the problem with the arrows like option+arrow only when I was in a remote server, using tmux from my machine. I guess that it was a server problem since I used the terminal of the server. Perhaps I should then of course rather add the setting on the server, but I did not want to touch it. Any comments welcome. Commented Jan 24, 2022 at 21:20
0

On my macOS High Sierra 10.13.6 the keys are not the same - they are:

nnoremap ^[OA <Up>
nnoremap ^[OB <Down>
nnoremap ^[OD <Left> 
nnoremap ^[OC <Right>

NB: This is not the functionality I was personally looking for and not sure what the tmux command does.

I want to stop the arrows keys opening and performing Mission Control actions. For that, I had to disable the keyboard shortcuts in Preferences.

See: How can I make ctrl+right/left arrow stop changing Desktops in Lion?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .