How do I run a macro on every line in a specific line number range?
:{range} normal @{reg}
The :normal command lets you execute Normal mode keystrokes over a range of lines.
2277 results for "@a"
:{range} normal @{reg}
The :normal command lets you execute Normal mode keystrokes over a range of lines.
:g/pattern/m$
The :g (global) command combined with :m (move) relocates all matching lines to a specified destination.
command-line #command-line #ex-commands #global #editing #organization
try | colorscheme gruvbox | catch | colorscheme default | endtry
How it works When you share your vimrc across multiple machines, a colorscheme you have installed on one system may not exist on another.
qaq qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until an error — such as reaching the end of the file — stops
:g/pattern/m 0
The :global command combined with :move lets you restructure a file by relocating all lines that match a pattern.
:set nofixendofline
By default, Vim enforces POSIX compliance by appending a final newline to any file that lacks one.
g* and g#
The and # commands search for the exact whole word under the cursor (with word boundaries \).
:set colorcolumn=80
The :set colorcolumn=80 command displays a vertical highlight at column 80, giving you a visual guide for line length.
:[range]center {width}
Vim has a built-in :center command that pads lines with leading spaces to visually center them within a given column width.
command-line #formatting #text-alignment #ex-commands #editing
:let @q .= "A;\<Esc>"
If a recorded macro is almost correct but missing a final step, re-recording from scratch is slow and error-prone.
gq (visual mode)
Pressing gq on a visual selection reformats the selected lines to hard-wrap at textwidth columns.
:mkspell ~/.vim/spell/en.utf-8.add
When you add words to your personal spell file with zg, Vim writes them to a plain-text .
"ap, edit, "add
Since macros are stored in registers, you can paste the register content into the buffer, edit it, and yank it back.
:let @q = substitute(@q, '\n$', 'A;<Esc>\n', '')
Rerecording a long macro for one tiny change is slow and error-prone.
"add
How it works When you delete text in Vim with commands like dd, dw, or x, the deleted text goes into the unnamed register and the numbered registers (1-9).
:tab drop filename
When working with many tabs, you often want to open a file — but only if it is not already open somewhere.
:let @/ = @"
After yanking text, you can promote it directly to the search register with :let @/ = @".
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:sandbox {cmd}
The :sandbox command modifier executes any Ex command in a restricted environment where potentially dangerous operations are blocked.
:while search('TODO') | normal! @q | endwhile
A fixed count like 100@q is brittle: sometimes your macro needs 12 passes, sometimes 300, and over-running can corrupt already-processed text.
macros #macros #automation #search #normal-mode #ex-commands