In Emacs, I can press Ctrl-h, k, to describe a key. I can get the key name even it's undefined, e.g.,

C-x <C-M-end> is undefined

Thus, I got to know the key name is C-x <C-M-end>.

But how can you get the key name for Vim?

I want to setup a keymap for Ctrl-Shift-V and Shift-Insert, but what the code shall I have to use?

Is it possible to get the key name on the fly?


The closest I can find to describe-key (Ctrl+H, K) is the :map command. It will list all mappings.

You can also run :map <key name>, but you have to specify <key> using the special syntax listed in

Or you can try :mapCtrl+V<key>, which should let you just press the key rather than needing to use the special syntax.

So to bind Ctrl+Shift+V, try this:

:map <C-S-v> whatever


:mapCtrl+V Ctrl+Shift+V whatever

But make sure that your terminal program doesn't already use this for something special like paste, otherwise Vim will never see the key press.

Also see map-alt-keys, which helps explain whether your Alt key should be written as <M-x> or <A-x>.

| improve this answer | |
  • It's Ctrl-h,k, not Ctrl-X,k which means kill buffer. – Xiè Jìléi Jan 20 '11 at 4:13
  • Sorry, fixed that. – Mikel Jan 20 '11 at 4:16
  • I'm not sure if M or A will be mapped to Alt. But <M-h>, <M-l> just don't work. I don't know whether the key name is invalid, or the key events haven't been sent to Vim. No log, no clue. – Xiè Jìléi Jan 20 '11 at 4:19
  • Yes, Alt is difficult, because most terminals send ESC then x when Alt+x is pressed, and how does Vim know you didn't press ESC then x. Basically Alt only works in Gvim. – Mikel Jan 20 '11 at 4:27

To find out what a key or key combination outputs in Vim, I usually open a blank buffer with ":enew", enter insert mode, press control-v, then the key or key combination I want to identify. This control-v trick can also work on the :-command line, so defining mappings for testing is fairly easy. For example, ":map ", control-v and the key combination, " :echo 'it works'".

| improve this answer | |

Just type Ctrl+V on-the-fly and the keys you wish to press. If you don't found the result expected (like for instance <c-space>, <c-cr>, <M-i>, ...) it just means you are using vim and not gvim. The way vim understands the keys typed is tied to the configuration of your terminal(s). gvim uses its own definitions, there is thus nothing to configure.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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