What is the difference between :norm and :norm! when running normal commands from the command line?
Answer
:norm! {cmd}
Explanation
Both :norm and :norm! execute a sequence of Normal mode keystrokes from the command line or a script, but they differ in how they handle user-defined mappings. :norm respects your custom key mappings, while :norm! bypasses them entirely and uses Vim's built-in behavior. This distinction is subtle but critical when writing scripts or using :norm inside :g commands.
How it works
:norm {keys}— plays back{keys}in Normal mode, running any user-defined mapping that matches:norm! {keys}— plays back{keys}in Normal mode, ignoring all mappings and using only built-in key behavior
This is analogous to map vs noremap: :norm is like calling a mapped key, :norm! is like using a non-recursive binding.
Example
Suppose your vimrc contains:
nnoremap w j
With this mapping, w moves down a line instead of jumping forward a word.
:norm w " runs the mapping → moves cursor down one line
:norm! w " ignores mapping → moves cursor forward one word (built-in)
In a global command this matters:
:g/TODO/norm dd " deletes line, but 'dd' could be remapped
:g/TODO/norm! dd " always deletes line using built-in dd
Tips
- In plugin code, always prefer
:norm!to avoid breaking users who have remapped common keys - Use
:norm(without!) only when you deliberately want the user's mappings to apply, for example when automating user-facing workflows - Both forms require the keys to be specified without a trailing
<CR>unless you explicitly want to press Enter as part of the sequence