Messed up keys in vim when running inside tmux

8

7

I have been playing with tmux and I'm loving it. However, there's an annoying issue when running vim inside it.

Somehow the arrow keys get remapped, but only on certain times, like when firing up Command-T, if I try to scroll down the file list, the command is cancelled and I'm thrown into insert mode, and depending on the arrow key I pressed, an A, B, C, or D is inserted.

If I use the arrows to move through a buffer for example, they work properly.

Any ideas?

Thanks!

Ivan

Posted 2011-01-25T19:30:21.500

Reputation: 3 639

1What is $TERM outside tmux? What about inside? It sounds like something is going on with application and normal keypad modes. – Paused until further notice. – 2011-01-25T20:26:10.990

Outside tmux: xterm, inside: screen... so if I run TERM=screen vim I see the same behavior, so I must fix screen? – Ivan – 2011-01-26T00:49:19.907

Answers

6

Finally I found my answer here: when running screen on OSX, command+r messes up arrow keys in vim across all screens

The weird thing is I only added ONE mapping to my .vimrc file:

map <Esc>[B <Down>

But that single mapping makes ALL the arrow keys work properly...

Ivan

Posted 2011-01-25T19:30:21.500

Reputation: 3 639

Somehow... this was the only solution that worked for me on Centos 6.3 – Patryk – 2013-08-20T11:20:55.573

This makes absolutely no sense to me, but adding a single mapping appears to fix all keys for me as well. Even stranger (at least to me) the direct mapping for the keypress in insert mode doesn't fix it (map ^[A <Up> works from pressing Ctrl+V <Up> and deleting the O, map ^[OA <Up> from pressing Ctrl+V <Up> and leaving the O doesn't). I don't get it...but whatever. My keys now work. Thank you. – ND Geek – 2013-08-26T20:01:38.447

12

I simply added set -g default-terminal "xterm" to my .tmux.conf

This made tmux use xterm instead of screen, so life is beautiful and I don't need to worry about stomping on keybindings.

Zee

Posted 2011-01-25T19:30:21.500

Reputation: 325

Not working in my case... – Blaszard – 2018-07-05T12:19:41.163

5Better like this set -g default-terminal "xterm-256color". Otherwise I couldn't notice when in visual mode due to limited colors. – Macario – 2012-02-18T11:39:32.520

1I had to combine this with set -g xterm-keys on. – Dan Stahlke – 2012-11-25T05:03:29.270

4It's worth noting that the man page for tmux says to never set default-terminal. I'm not sure what the ramifications are. – Dan Stahlke – 2012-11-25T05:33:39.843

1

Given the warning that default-terminal should not be set, there is perhaps a better fix from the vim side: link.

– Dan Stahlke – 2012-11-25T14:34:13.493

1

The xterm and xterm-256color causes the BCE problem. See http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1932.

Hallison Batista

Posted 2011-01-25T19:30:21.500

Reputation: 111

1

Just in case someone happens to get mad with this solutions not working.

Check out that you don't are actually using tmux + vim + AutoClose vim plugin. Autoclose maps something that causes you having ABCD chars inserted in the previous line!

I just erased the plugin and it's working alright now

txomon

Posted 2011-01-25T19:30:21.500

Reputation: 137

Thank you! This was it for me. I ended up using this autoclose-plugin instead. It provides similar functionality.

– ollpu – 2017-01-06T23:39:59.883

0

Command-T does something dumb by mapping when running in a terminal. It skips the mapping if $TERM is vt100* or xterm*, but that's not a good solution.

graywh

Posted 2011-01-25T19:30:21.500

Reputation: 197

0

For those people that want to move the cursor in command line mode, take a look at this blog post. I ended up adding eight lines in my vimrc;

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

" Console movement
cmap <Esc>[A <Up>
cmap <Esc>[B <Down>
cmap <Esc>[C <Right>
cmap <Esc>[D <Left>

frbl

Posted 2011-01-25T19:30:21.500

Reputation: 101