Question

Attempting to add a normal mode mapping in vim for Control + Enter to insert line break above cursor positon

:nmap <C-CR> O<Esc>

I am finding this does not work - what am I missing here?

Was it helpful?

Solution

This is probably based on your terminal rather than vim. You can tell what key your terminal sends by <C-Enter> via C-V C-Enter. Most likely this is a newline which you can use as <NL> in vim.

:nmap <NL> O<Esc>

OTHER TIPS

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today; though this particular mapping should work in GVIM, but not in most terminals. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) 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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top