In vim, input is mapped to the ctrl key custom key card

I am facing some weird behavior using a key card in vim that uses the ctrl key. I would suggest that this has a simple reason and solution, but I just don't see it.

While editing a restructured text, I find things like

:math:`x` 

often (this: math: role will cause everything inside the ticks to be typed like math, for example, latex output).

I want to map a key such as m to type: math: `` in the text and place the cursor inside the ticks.

I did it

 map mi:math:``ha 

and it seems to be working fine.

However, I would like to be able to use this card in insert mode. For this, I thought it was better to use ctrl + m . I did

 imap <cm> :math:``ha 

Although this correctly enters: math: `` and positions the cursor inside the ticks when I do ctrl + m , the problem is that after this point every time I press enter in insert mode, this executes the same command as if I typed ctrl + m . In other words, entering insert mode now seems to be displayed on

 :math:``ha 

.

This seems to be definitely related to using the ctrl key. If I tie, for example. F5 key as follows

 imap <F5> :math:``ha 

everything is good.

I can use, for example, F5 and keep myself further concerned, but I would like to know what is happening for future reference.

Is there anything basic about using the ctrl key in a key card that I am missing?

Thank you,

+4
source share
2 answers

You need to use a different control combination for your comparison, for example. <Cg> .

Due to the fact that keyboard input is processed internally, this, unfortunately, is not possible today without these side effects, even in GVIM. Some key combinations, such as Ctrl + non-alphabet, cannot be displayed, but Ctrl + letter vs. Ctrl + Shift + letter cannot be selected. (If your terminal does not send a separate termcap code for it, which is most missing.) This also applies to <Tab> / <CI> , <CR> / <CM> / <Esc> / <C-[> , etc. d. (The only exception is <BS> / <CH> .) This is a known pain point and the subject of various discussions of the vim_dev and #vim IRC channels.

Some people (primarily Paul Leo Nord Evans) want to fix this (even for the Vim console in terminals that support this), and have issued various suggestions, cf. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But to date, no patches or volunteers have yet been released, although many have expressed a desire to have this in a future release of Vim 8.

+7
source

if you follow

 :h keycodes 

you will see:

 notation meaning equivalent decimal value(s) ~ ----------------------------------------------------------------------- .... <CR> carriage return CTRL-M 13 *carriage-return* <Return> same as <CR> *<Return>* <Enter> same as <CR> *<Enter>* 

therefore it reports that <cm> matches <Enter> (same key code 13)

you can also check in your shell, for example, type ls and then <cm> instead of <Enter>

+1
source

All Articles