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.

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" 
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.