6

I am using macvim 8.1, the map command is

:inoremap <C-$> <End>

I also tried <C-4>, no working.

tried other number, can't work too (however CTRL-6 could work).

Also tried nnoremap, same result.

the :map <C-$> command shows

i <C-$>      * <End>
chrisyue
  • 203
  • 2
  • 5

2 Answers2

9

Normally Ctrl-Number produce a different key code. You can check like this:

Open Vim and change to insert mode. Then hit Ctrl-V followed by Ctrl-4 (or whatever you plan to map).

On Linux this produces the output ^\. Note that this is one character, usually displayed in light-blue. So Ctrl-4 is identical to Ctrl-\.

Tested with Vim 8.1 on Ubuntu in Gnome-Terminal (but should be true for all systems):

  • Ctrl-1 is not detected
  • Ctrl-2 is Ctrl-@ (hex 0x00)
  • Ctrl-3 is Ctrl-[ aka ESC
  • Ctrl-4 is Ctrl-\
  • Ctrl-5 is Ctrl-]
  • Ctrl-6 is Ctrl-^
  • Ctrl-7 is Ctrl-_
  • Ctrl-8 is Ctrl-? aka Delete used as Backspace
  • Ctrl-9 is not detected
  • Ctrl-0 is not detected
Ralf
  • 9,197
  • 1
  • 11
  • 30
  • 2
    Also, please see the faq: https://vimhelp.org/vim_faq.txt.html#faq-20.5 – Christian Brabandt Mar 29 '19 at 10:51
  • If Ctrl-3 is identical to ESC, I should expect vim quit insert mode to normal mode when Ctrl-3 is pressed, like ESC usuallly does, however, actually, 3 is input, so Ctrl-3 shouldn't be the same as ESC or Ctrl-[, should it? – chrisyue Apr 01 '19 at 02:16
  • @chrisyue <Ctrl-3> leaves insert mode. Tested in Vim, GVim, and the vi-editing-mode of Bash (Gnome-Terminal, XTerm). – Ralf Apr 01 '19 at 04:47
  • Well, on a mac at least <C-6> doesnt work, you have to use <C-^> – D. Ben Knoble Feb 27 '20 at 06:03
1

I had a similar issue, when I wanted to map Ctrl+4 and Ctrl+6 keys, but those codes were not recognized. The output of Ctrl+vCtrl+4 was ^[[1;5t, which usually would lead to a mapping like e.g.

map ^[[1;5t <End>

but that did not work. The solution was to replace ^[ with <ESC> in the mapping command, like e.g.:

map <ESC>[1;5t <End>
imap <ESC>[1;5t <End>
t0r0X
  • 111
  • 3
  • Note: ■ Generally speaking, mapping raw key sequences like shown is not a good idea, as then pressing will be delayed. ■ of course you can write ^[ directly in vim editor, just enter it as the raw escape byte (by , the ^[ should be colored blue) – user202729 Feb 17 '23 at 02:34