#77 Mapping C-Arrow in Vim

closed
nobody
None
2014-02-26
2013-11-12
Paul Gideon Dann
No

Not so much a bug as a comment regarding the FAQ, which mentioned that examples of how to map special keys in Vim without requiring xterm-keys would be welcome.

From the following:
https://github.com/godlygeek/vim-files/blob/master/plugin/terminalkeys.vim

I came to this "simplified" solution:

set ttimeoutlen=100
if &term == 'screen'
  set <F25>=^[[A
  map <F25> <C-Up>
  map! <F25> <C-Up>
  set <F26>=^[[B
  map <F26> <C-Down>
  map! <F26> <C-Down>
  set <F27>=^[[C
  map <F27> <C-Right>
  map! <F27> <C-Right>
  set <F28>=^[[D
  map <F28> <C-Left>
  map! <F28> <C-Left>
endif

For some reason, Vim receives ^[OA for <Up> and ^[[A for <C-Up>, whereas cat -v receives them the other way around, in the same session. No idea why, but this works. There are no terminfo keycode names we can set directly for <C-Up> and friends, but it's important that we not simply map the escape sequence to the final <C-Up> using map, because that would result in an annoying delay when pressing <Esc> to leave insert mode. Specifying ttimeoutlen allows us to greatly reduce the length of time Vim waits after receiving an <Esc> code before deciding it wasn't one of these combinations.

Discussion

  • The reason the input changes is probably that vim turns on "cursor keys mode" (tput smkx) and tmux follows putty (I forget why) and changes the cursor keys as you see.

    Any chance you can write these instructions simply as a diff against the FAQ file?

    terminfo was fairly recently extended to for kUP5 for C-Up (and kDN5, kLFT5, kRIT5), but I have no idea if Vim recognises them.

     
    • status: open --> closed
    • Milestone: -->