How do you execute a normal mode command on a range of lines?
:%normal A;
Use :%normal followed by normal mode keystrokes.
953 results for ":normal"
:%normal A;
Use :%normal followed by normal mode keystrokes.
:%normal command
The :normal command executes normal mode commands programmatically on a range of lines.
:execute "normal! gg=G"<CR>
:execute lets you build and run Ex commands dynamically, which is critical when a command depends on variables, conditionals, or string composition.
command-line #command-line #ex-commands #normal-mode #automation
:normal! {keys}
:normal {keys} executes keystrokes as if typed in Normal mode — but it respects your custom mappings and abbreviations.
:normal!
The :normal! command (with !) executes normal mode keystrokes exactly as Vim defines them, ignoring any user-defined mappings.
:normal! {cmds}
:normal {cmds} executes normal-mode keystrokes from the command line, but it honors your custom key mappings — so remapped keys produce unexpected results in
command-line #ex-commands #macros #normal-mode #command-line
qaq:g/pattern/normal "Ayy
Clear register a with qaq, then use :g/pattern/normal "Ayy to append all matching lines to register a.
:g/pattern/normal A;
The :global command combined with :normal lets you execute arbitrary normal mode keystrokes on every line that matches a pattern.
command-line #global #normal-mode #editing #ex-commands #batch-editing
:normal! {cmd}
When you use :normal {cmd} in a Vimscript function, macro, or Ex command, Vim expands any keys through the user's current mappings first.
:'<,'>normal {command}
After making a visual selection, :'normal {command} runs any normal-mode command on each selected line individually.
:g/pattern/normal dd
The :g/pattern/normal {commands} command executes normal mode keystrokes on every line in the file that matches the given pattern.
:execute "normal! \<{key}>"
When building dynamic :execute normal! calls in Vimscript, you must use double-quoted strings with the \ notation so Vim interprets the special key codes.
:'<,'>normal A;
The :normal command executes normal-mode keystrokes on every line in a range.
command-line #command-line #ex-commands #editing #normal-mode #batch-editing
:'<,'>g/let /normal! A;<CR>
When you need a structural edit in part of a file, Visual mode ranges combine well with :global and :normal!.
visual-mode #visual-mode #command-line #ex-commands #editing
:'<,'>normal! A;
Visual selections are not just for direct operators; they also define an Ex range.
visual-mode #visual-mode #normal-mode #editing #ex-commands #automation
:g/[^[:space:]]/normal! A;\<CR>
When you need to patch many lines at once, :g with :normal! is often faster and safer than recording a macro.
command-line #command-line #ex-commands #editing #normal-mode
:%normal @q
To apply a macro to every line in the file, use :%normal @q.
:undojoin | normal! A;<CR>
When you automate edits from Ex commands, Vim usually creates a separate undo entry for each change.
:g/^/normal I// <CR>
When you need to comment a whole block quickly, :global combined with :normal is faster than recording a macro or entering Visual Block mode.
:'<,'>normal! .
When you already made one correct edit, replaying it is usually safer than retyping it by hand.