2

I want to map

  • semicolon (;) to Escape
  • Ctrl+semicolon to semicolon

and wrote the following in my .vmrc

  1. inoremap ; <ESC>

  2. inoremap <C-;> ;

(1) allows me to escape from the insert mode, but (2) also behaves like Escape rather than giving ;.

What am I missing here? Any help is appreciated.

4
  • 8
    I suspect <c-;> is the same as ; in your terminal. Press Ctrl-V and then Ctrl-;, you'll likely see just ;.
    – muru
    Commented May 17, 2016 at 1:19
  • Ctrl-V and then Ctrl+; give ;, indeed. Ctrl-V and then ; also give ;. Isn't Ctrl-V the blockwise-visual mode?
    – T_T
    Commented May 17, 2016 at 4:24
  • :help i_ctrl-v… Vim is a modal editor.
    – romainl
    Commented May 17, 2016 at 5:10
  • 1
    @muru: confirmed here in iterm2, tmux, zsh, as well as the macvim gui.
    – nobe4
    Commented May 17, 2016 at 8:23

3 Answers 3

4

It looks like <C-;> does not work in vim. Might I suggest using <A-;> (Alt) instead? That one seems to work for me.

1
  • Thanks for the suggestion, but I want to use Ctrl+; to type ;.
    – T_T
    Commented May 18, 2016 at 1:02
3
  1. The C-; is not available for you to remap in any variety of VI.
  2. Even in a GUI evironment, I don't see any chance that can help you.
  3. I hope the following explanation can convince you of the fact.

  1. Please look at the ascii table, which has 4 columns of code/characters - from right to left, lowercase alphabets, uppercase alphabets, symbols/numbers, and non-printable code (or called CTRL characters) - basically only these Ctrl keys are supported. And you have the Ctrl-F1 up to Ctrl-F12 as bonus. ASCII Table

  2. The keyboard has come a long way since about 40 years ago. In the good old days when the terminal was invented, these 128 code/characters were all we have and all we need. We made use of the first 32 code to control the position of cursor in terminal as well as commnunication.

  3. The keyboard interprets what you type and sends two bytes to computer - one is character code, the other is scan code. (since about 30 years ago. I'm not clear about the beginning.) For the range of ASCII, it sends a character code of Dec in blue column, and a scan code of 0.

  4. You get code of [a-z] when you type directly. You get code of [A-Z] when you type w/ modifier SHIFT. You get code of [0-9] when you type the upper row. You get code of symbols when you type the numbers w/ SHIFT. Finally you get the CONTROL code exactly when you type the character w/ modifier CTRL. Look! This is what the keyboard does/interprets for you (smart enough. The mapping rules were still simple.).

  5. Soon we felt 128 code is not enough and invented Alt etc. modifiers. I think the scan code was introduced at that time. All the Alt-related key combinations require a non-zero scan code. It's also true for the arrow keys in Keypad. The mapping rule become complicated.

  6. Because of such long-time historical progress, you'll find that those modifiers CTRL, SHIFT, ALT (and even Win, Fn) are not treated fairly...SHIFT and ALT can modify more keys, but CTRL the least. (Sorry for your Ctrl-;) (I believe it's for backward compatibility.)

  7. Although it's not impossible or definitely difficult to add more Ctrl keys, like the Ctrl-1...Ctrl-9 available in GUI Desktop, I don't think it's a good idea for VI - VI has been designed to work both for terminal and new GUI environments. It has to be consistent for both. However, making such changes in terminal protocols is not easy.


1
  • I found it works fairly well to invent control sequences of your own but it does mean that you have to configure all apps to handle them properly. For example I use vim and tmux so whatever custom escape sequence you've configured your terminal to emit, for a given key you have to figure out how to convince tmux to pass it through and for vim to recognize it. I use tmux's user-keys settings to do this nowadays but it also has F-keys going up to a large number and those worked too
    – Steven Lu
    Commented Mar 14, 2023 at 23:27
2

Ctrl-; is not a valid control sequence, so vim cannot capture it. You will need to use gvim or to configure your terminal emulator to translate Ctrl-; to something vim can capture

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.