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

How do I run a normal mode command from the ex command line without triggering my custom key mappings?

Answer

:norm! {command}

Explanation

:normal {command} runs a sequence of Normal mode keystrokes from the command line (or a range of lines with :%normal), but it applies your custom key mappings. Add a bang — :normal! {command} — and Vim executes the raw, built-in command without any remapping. This distinction is critical when writing portable scripts, functions, or macros that must behave identically regardless of the user's configuration.

How it works

  • :norm {cmd}: applies mappings — if you have nnoremap x dd, :norm x runs dd
  • :norm! {cmd}: ignores all mappings — :norm! x always deletes a single character
  • The ! variant guarantees predictable, mapping-independent behavior
  • Works with ranges: :%norm! A; appends a semicolon to every line using the built-in A, regardless of any A remapping
  • Accepts the full <CR>, <Esc>, and other special key notations when invoked from a function via execute

Example

Suppose you have nnoremap w b in your config to reverse w and b. Running:

:%norm w

behaves like b (your remapping), not w. But:

:%norm! w

always moves to the next word boundary as the built-in w normally does.

Tips

  • Always use :norm! inside autocommands, plugins, and shared vimrc snippets to avoid mapping conflicts
  • Combine with a range to apply a Normal command to every line: :'<,'>norm! >> indents all selected lines using the real >>, not a remapped version
  • Use :execute "norm! \<C-a>" in scripts when the command includes special keys

Next

How do I combine two recorded macros into one without re-recording them from scratch?