48
29
This is all in iTerm2 on OS X.
I used to have
export TERM='xterm-256color'
in my .bashrc
. This meant Vim in tmux did use 256 colors.
And once I added
set -g xterm-keys on
then keyboard shortcuts with modifiers worked fine in Vim. Namely: shift+left/right
that I mapped to switch Vim tabs, ctrl+up/down
that I mapped to move ("bubble") lines, and shift+left/right
which worked out of the box to jump by word in the command-line mode (e.g. when typing something like :e foo bar baz
).
However, this setup had the problem that the Vim background color only shows behind text, as mentioned here.
So I removed
export TERM='xterm-256color'
from my .bashrc
and instead put this in my .tmux.conf
:
set -g default-terminal "screen-256color"
That fixed the Vim background color, but broke the keyboard shortcuts - they do unexpected things (move the cursor, delete text) instead.
By using ctrl+v
to insert the verbatim output from the key combinations (as described here), I was able to work around it:
map [1;5A <C-Up>
map [1;5B <C-Down>
map [1;2D <S-Left>
map [1;2C <S-Right>
cmap [1;2D <S-Left>
cmap [1;2C <S-Right>
This makes the shortcuts work, but it doesn't feel like the right solution. Could anyone tell me what's happening here and how to fix it?
@HenrikN Could you please clarify what
map <Esc>[B <Down>
does? I don't see any difference by adding it to my .vimrc file. – Tropilio – 2019-04-10T12:01:11.717@Francesco Boccardo: If you follow the link in my previous comment, and then follow the link again from there, you get to https://superuser.com/a/215181 which seems to explain it in excruciating detail :)
– Henrik N – 2019-04-10T18:54:32.683@HenrikN Thanks. So it is probably an OSX related issue, or maybe it's been resolved in these 7 years, because pressing command (control?) + r doesn't mess up the arrow keys in vim in tmux for me (I am on Linux). – Tropilio – 2019-04-11T07:39:32.850
Thank you! That looks better than what I had, and I appreciate the explanation. One thing that was fixed by what I had, but not by your lines, was that up/down arrows didn't work in the Command-T plugin as described here: http://superuser.com/questions/237751/messed-up-keys-in-vim-when-running-inside-tmux I just added
– Henrik N – 2012-03-18T20:51:45.380map <Esc>[B <Down>
from one of the answers. Seems the reason there is some bad assumptions made by the plugin itself.Just to be clear, your solution plus
map <Esc>[B <Down>
from that other thread means everything now works fine. – Henrik N – 2012-03-18T21:02:43.717