DamZiobro / vim-ide

VIM configured as powerful IDE (Integrated Development Environment)
MIT License
471 stars 94 forks source link

Arrow keys are not working in tmux #10

Open sharkvan opened 6 years ago

sharkvan commented 6 years ago

I'm a real fan of this setup. But I also really like tmux. When I run vim now in tmux my arrow keys kick me out of insert mode and print a,b,c, or d on a new line until I hit the ESC key. I'm not sure how to begin to debug this so I can fix it. But I would love it if someone either knows how to fix it or can point me to how I would start to debug it. Just to clarify, everything works fine outside of tmux.

DamZiobro commented 6 years ago

could you paste your tmux arrow keys shortcuts from tmux config file here?

sharkvan commented 6 years ago

This is my tmux config file

# 0 is too far from ` ;)
set -g base-index 1
set -g default-terminal screen-256color
set -g mouse on
set -g monitor-activity on
bind > setw synchronize-panes

# No delay for escape key press
set -sg escape-time 0

# Reload tmux config
bind r source-file ~/.tmux.conf

#Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

#Continuum Settings
set -g @continuum-restore 'on'

#Vim restore settings
set -g @resurrect-strategy-vim 'session'

#Initialize TMUX plugin manager (Keep this line at the very bottom of the config file)
run '~/.tmux/plugins/tpm/tpm'

And here are all the keys that tmux list-keys reports as being bound to arrow keys.

bind-key    -T copy-mode    Up                send-keys -X cursor-up
bind-key    -T copy-mode    Down              send-keys -X cursor-down
bind-key    -T copy-mode    Left              send-keys -X cursor-left
bind-key    -T copy-mode    Right             send-keys -X cursor-right
bind-key    -T copy-mode    M-Up              send-keys -X halfpage-up
bind-key    -T copy-mode    M-Down            send-keys -X halfpage-down
bind-key    -T copy-mode    C-Up              send-keys -X scroll-up
bind-key    -T copy-mode    C-Down            send-keys -X scroll-down
bind-key    -T copy-mode-vi Up                send-keys -X cursor-up
bind-key    -T copy-mode-vi Down              send-keys -X cursor-down
bind-key    -T copy-mode-vi Left              send-keys -X cursor-left
bind-key    -T copy-mode-vi Right             send-keys -X cursor-right
bind-key    -T copy-mode-vi C-Up              send-keys -X scroll-up
bind-key    -T copy-mode-vi C-Down            send-keys -X scroll-down
bind-key -r -T prefix       Up                select-pane -U
bind-key -r -T prefix       Down              select-pane -D
bind-key -r -T prefix       Left              select-pane -L
bind-key -r -T prefix       Right             select-pane -R
bind-key -r -T prefix       M-Up              resize-pane -U 5
bind-key -r -T prefix       M-Down            resize-pane -D 5
bind-key -r -T prefix       M-Left            resize-pane -L 5
bind-key -r -T prefix       M-Right           resize-pane -R 5
bind-key -r -T prefix       C-Up              resize-pane -U
bind-key -r -T prefix       C-Down            resize-pane -D
bind-key -r -T prefix       C-Left            resize-pane -L
bind-key -r -T prefix       C-Right           resize-pane -R

Thanks for you help.

henczati commented 6 years ago

+1

I can confirm it on both using a Cygwin terminal on Windows 10 connected to an Ubuntu 16.04.4 server through ssh and a vte console/terminal locally.

The problem exists when trying to move the cursor with the arrow keys in insert mode.

In a plain terminal the arrow keys move the cursor correctly, but they exit insert mode (stays in normal mode).

In tmux the behaviour is similar than when vim is run in vi compatibility mode: in normal mode the arrows move the cursor correctly, but in insert mode they (I guess) exit and reenter insert mode and put a new line just above the last cursor position with a single uppercase letter depending on the arrow key pressed: A (up), B (down), C (right), D (left). I think the letter is the same as in the arrow key's character representation.

This might help: Fix arrow keys that display A B C D on remote shell

Other vim ide configurations I tried (vim-ide by sebdah, yavide) do not have this issue.

I use the default tmux keybindings. My .tmux.conf:

#set -g default-terminal "screen-256color"
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel -i --clipboard"

### This must be at the bottom ###

set -g @continuum-restore 'on'

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-copycat'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
wilhelmloof commented 1 year ago

I know this is an old thread, but I just had this issue and solved it by adding set nocompatible to ~/.vimrc.