Vim and Tmux – How to Get Vim to Work with Tmux Properly

keyboard shortcutstmuxvim

I'm trying to figure out how to get vim and tmux play together.

My problem is:
When I use xterm-256color I get vim to work nicely, but the background doesn't render properly.

I fixed this by using screen-256color. This looks nice but breaks the Ctrl + arrow keys (they go in insert mode and delete 4 lines). I want to use these mappings instead to switch tabs in vim.

How do I get this to work?

Best Answer

Run cat within tmux and press the keys in question to find out the escape codes they generate. For me this gives ^[[D and ^[[C. Then just map those escape codes directly.

nnoremap ^[[D gT
nnoremap ^[[C gt

where the ^[ is an escape character, that you can insert by pressing <CTRL-v><ESC> in vim.

Related Question