vimtricks.wiki Concise Vim tricks, one at a time.

How do I run a :normal command that ignores user-defined mappings?

Answer

:normal! {cmds}

Explanation

:normal {cmds} executes normal-mode keystrokes from the command line, but it honors your custom key mappings — so remapped keys produce unexpected results in scripts. Adding ! forces Vim to use its built-in behavior exclusively, making automation reliable regardless of any user configuration.

How it works

  • :normal {cmds} — runs the keystrokes as if typed in normal mode, applying user nmap/nnoremap definitions
  • :normal! {cmds} — runs the same keystrokes but skips all mappings, using only Vim's native behavior

The ! is critical in:

  • Vimscript functions and plugins (must work on every user's setup)
  • :global commands paired with :normal
  • Automation that must behave identically regardless of .vimrc

Example

If you've remapped w to a smart jump function:

:normal w    " triggers your custom mapping — unpredictable in a script
:normal! w   " always moves to the next word — built-in behavior

Used with a range to safely append a semicolon to every line:

:%normal! A;

Or with :global to comment all function definitions:

:g/^\s*def /normal! I# 

Tips

  • Always use :normal! in plugin code and shared scripts — never :normal
  • Works with any range: :5,10normal! >> indents lines 5–10
  • To include a literal <Esc> or <CR>, type <C-v><Esc> or <C-v><CR> when entering the command
  • Combine with :silent! to suppress errors during bulk operations: :silent! %normal! @q

Next

How do I highlight all occurrences of a yanked word without typing a search pattern?