Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't this .vimrc mapping work in terminal (but it does in MacVim): map <S-Enter> O<Esc>

Tags:

vim

I have two lines in my .vimrc file:

map <S-Enter> O<Esc>
map <CR> o<Esc>

The second line works as expected, but the first line does not.

The idea is that if I hit the Enter key then vim should insert a new line below the cursor position and move the cursor down to that line. If I hit Shift-Enter, vim should insert a new line above the cursor position and move the cursor up to that line. This mapping should work because the capital O key from normal mode will insert a newline above the line the cursor is on, place the cursor at the beginning of that line, and then place the user into insert mode. Capital O followed by <Esc> should simply revert vim back to command mode.

I have checked and capital O works as I expect. So why doesn't my mapping work? I have tried using map <Shift-CR> and map <Shift-Enter>, and neither of those does the trick.

EDIT Turns out it works in MacVim but not in iTerm. If anyone can explain why and suggest a workaround, I'd appreciate it.

like image 934
tadasajon Avatar asked Oct 25 '12 16:10

tadasajon


1 Answers

Are you using console Vim? Some key combinations can only be mapped in GVIM. In all / most Linux terminals, Enter cannot be combined with Shift or Ctrl. Your mapping per se is correct, but you'd have to use a different LHS in the mapping.

Due to the way that the keyboard input is handled internally, some key combinations cannot be used even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

like image 58
Ingo Karkat Avatar answered Oct 05 '22 15:10

Ingo Karkat