Mode – aware remapping

The :map and :noremap commands work for normal, visual, select, and operator pending modes. Vim supports a more fine-grained control over which modes the mappings work in:

  • :nmap and :nnoremap: Normal mode
  • :vmap and :vnoremap: Visual and select modes
  • :xmap and :xnoremap: Visual mode
  • :smap and :snoremap: Select mode
  • :omap and :onoremap: Operator-pending mode
  • :map! and :noremap!: Insert and command-line modes
  • :imap and :inoremap: Insert mode
  • :cmap and :cnoremap: Command-line mode
Vim often uses an exclamation mark ! to force command execution, or to add additional functionality to a command. Try :help! for yourself!

For example, if you wanted to add some mappings to alter some insert mode behavior, you could do this:

" Immediately add a closing quotes or braces in insert mode.
inoremap ' ''<esc>i
inoremap " ""<esc>i
inoremap ( ()<esc>i
inoremap { {}<esc>i
inoremap [ []<esc>i

In the preceding example, we changed the default behavior of a key press in insert mode (for example, the opening square bracket [) to insert two characters instead of one ([]), leave insert mode, and immediately reenter it (to be placed between both braces, since insert mode is entered before the cursor).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.33.87