Step 2 of 6

10. Make Vim Your Own With Maps

Fundamentals of mapping with Vim

At a fundamental level, remapping with Vim is just saying “whenever these keys are typed, pretend that I typed these other keys instead”. So, the following mapping from earlier:

:inoremap ' ''<left>

is really just saying “whenever I type a ', pretend that I typed '', followed by the left arrow key”.

Mapping in different modes

You can create maps for any Vim mode — the available mapping commands are:

  • :map for mapping in normal mode, visual mode, select mode, and operator pending mode all at once
  • :nmap for mapping in normal mode
  • :vmap for mapping in visual mode and select mode at the same time
  • :smap for mapping in select mode
  • :xmap for mapping in visual mode
  • :omap for mapping in operator pending mode
  • :imap for mapping in insert mode
  • :cmap for mapping in command-line mode
  • :tmap for mapping in Vim’s built-in terminal

Work through the checklist below: define the normal mode map and the insert mode map suggested in the demo, and try each one out right after you create it.

What does noremap mean?

noremap means “don’t try to recursively execute this map”. Consider the mapping from earlier:

:inoremap ' ''<left>

If we didn’t have noremap here and instead used:

:imap ' ''<left>

Then, when you type ', Vim would try to recursively look up the mapping for the ' character, causing Vim to hang. noremap squashes this behavior. If in doubt, you probably want to be using noremap!

  1. Map Enter to jump to the top The demo suggests nnoremap for this one — type :nnoremap <cr> gg and hit Enter.
  2. Use your normal mode map Your new map runs gg and carries you back to the top — jump to the bottom with G first, then press Enter.
  3. Map jk to leave insert mode A classic insert mode remap — type :inoremap jk <esc> and hit Enter.
  4. Use your insert mode map Enter insert mode with i, then type jk — you pop back to normal mode without touching the Escape key.
Map Enter to jump to the top The demo suggests nnoremap for this one — type :nnoremap <cr> gg and hit Enter.

Next: Use your normal mode map

Loading editor…