How do I make my macros robust regardless of cursor position?
0 or ^ at start of macro
A common macro pitfall is assuming the cursor starts at a specific column.
57 results for "line start 0"
0 or ^ at start of macro
A common macro pitfall is assuming the cursor starts at a specific column.
:g/^/m 0
This clever use of the :global command reverses every line in the current buffer.
command-line #editing #ex-commands #global #text-manipulation
g0
When wrap is on, a long buffer line can span multiple screen (display) lines.
navigation #navigation #motions #wrap #display-lines #normal-mode
^ vs 0
Vim has two distinct motions for moving to the start of a line: 0 goes to column 1 (the absolute start), while ^ goes to the first non-blank character.
navigation #navigation #motions #line-navigation #indentation
:clearjumps
The :clearjumps command wipes the jump list for the current window, giving you a clean slate for and navigation.
<C-v>jjjg<C-a>
Selecting a column of identical numbers with visual block mode and pressing g turns them into an incrementing sequence.
/<C-r>0
How it works After yanking text, you can use it directly as a search pattern by inserting the yank register contents into the search prompt.
<C-x><C-u>
Vim's invokes a user-defined completion function, letting you plug any completion logic you want into the standard insert-mode completion popup.
:call timer_start(1000, {-> execute('echo "done"')})
Vim's timerstart() function lets you schedule code to run after a specified delay in milliseconds.
:%s/#\zs\d\+/\=printf('%04d', submatch(0))/g
For log files, changelogs, or issue references, you sometimes need fixed-width numeric IDs without touching surrounding syntax.
editing #editing #ex-commands #substitute #regex #text-processing
qa0f:dwj0q
How it works When recording a macro that you plan to repeat across multiple lines, the key technique is to end the macro positioned on the next line, ready for
[/
When editing code, you often need to navigate to the boundaries of multi-line block comments (/ .
"qp {edit} 0"qy$ dd
When you record a macro and realize it has a mistake, the easiest fix is to paste the macro's keystrokes as text, edit them, and yank the corrected version back
qa0dwjq
Record a macro that goes to the start of line with 0, deletes the first word with dw, and moves down with j.
:/pattern1/,/pattern2/
Ex command ranges in Vim are not limited to line numbers and marks — you can use /pattern/ as a range boundary to select lines between any two matching patter
\%^ and \%$
Vim's ^ and $ anchors match the start and end of a line, but sometimes you need to match the very beginning or very end of the entire buffer.
g<C-a> in visual mode
When you have multiple lines with the same number and want to turn them into a sequence (1, 2, 3.
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:s/pattern/\=expr/
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
:normal! {keys}
:normal {keys} executes keystrokes as if typed in Normal mode — but it respects your custom mappings and abbreviations.