How do I run Normal mode commands in a script without triggering my custom mappings?
:normal! {keys}
:normal {keys} executes keystrokes as if typed in Normal mode — but it respects your custom mappings and abbreviations.
:normal! {keys}
:normal {keys} executes keystrokes as if typed in Normal mode — but it respects your custom mappings and abbreviations.
When recording a macro, you can execute another macro inside it by pressing @b (or any register) during the recording.
:ldo execute 'normal @q'
:ldo runs an Ex command on each entry in the location list — the buffer-local cousin of the quickfix list.
:argdo execute 'normal @q' | update
:argdo runs an Ex command on every file in Vim's argument list (the arglist).
:let @q = '{keystrokes}'
You can assign a string directly to any register using :let @{reg} = '.
:%normal @q
To apply a macro to every line in the file, use :%normal @q.
:'<,'>norm @q
When you visually select lines and then type a : command, Vim automatically inserts ' (the visual range marks) into the command line.
"qp
Macros are stored as plain text in named registers.
100@a
When you give a large count to a macro — such as 100@a — Vim automatically stops replaying the macro as soon as any step inside it fails.
@=
The @= command lets you type a Vimscript expression and execute the result as if it were a macro.
"ap, edit, 0"ay$
When a macro has a small mistake, re-recording the entire thing is tedious.
qaciWmyFunc(<C-r>")<Esc>q
Record a macro that changes the inner word, types the function name with opening paren, pastes the original word from the register, and closes the paren.
qaq:g/pattern/normal "Ayy
Clear register a with qaq, then use :g/pattern/normal "Ayy to append all matching lines to register a.
qaddpq
Record a macro that deletes the current line with dd and pastes it below the next line with p.
qagUlwq
Record a macro that uppercases the first letter of the current word with gUl, then moves to the next word with w.
qa/true\|false\ncgn<C-r>=@"=='true'?'false':'true'\n<Esc>q
Record a macro using cgn with an expression register to toggle between true and false.
:let @a='...' in vimrc
Add let @a='macro-keystrokes' to your vimrc file to have the macro available in every Vim session.
qavip:sort\n}jq
Record a macro that visually selects the inner paragraph, sorts its lines, then moves to the next paragraph.
qa80|i\n<Esc>jq
Record a macro that moves to column 80 using 80 , inserts a newline, and moves to the next line.
qayy:+1\nif getline('.')==@0|d|else|+1|endif\nq
Record a macro that yanks the current line and compares it with the next.