How do I make a macro conditionally execute commands based on line content?
:if condition | execute 'normal cmd' | endif
How it works Vim macros can include Ex commands with conditional logic.
1019 results for "i" a""
:if condition | execute 'normal cmd' | endif
How it works Vim macros can include Ex commands with conditional logic.
:g/pattern/norm @a
The :g/pattern/norm @a command combines the global command with macro execution.
:v/pattern/command
:v (short for :vglobal) is the inverse of :g.
<C-a>
The command increments the number under or after the cursor by 1.
<C-v>jj$A;
Visual block mode normally selects a fixed-width column, which makes appending tricky when lines have different lengths.
<C-o>
The (Ctrl+o) command jumps the cursor backward through the jump list, returning you to previous cursor positions.
:term then <C-w>N for normal mode
Vim 8+ and Neovim have a built-in terminal emulator that runs inside a buffer.
command-line #command-line #terminal #workflow #productivity
g; / g,
The g; and g, commands let you navigate Vim's changelist — a per-buffer history of every position where you made a change.
navigation #navigation #changelist #editing #normal-mode #marks
u after macro (single undo)
When a macro makes multiple changes, a single u undoes the entire macro as one unit.
qA
If you finish recording a macro and realize you forgot a step, you don't need to re-record the whole thing.
macros #macros #registers #normal-mode #editing #productivity
:set winfixwidth winfixheight
How it works When you open new split windows in Vim, the existing windows automatically resize to make room.
"=
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
m{a-z} then '{a-z}
Vim marks let you bookmark positions in a file and jump back to them instantly.
<C-v>I#<Esc>
Vim's Visual Block mode lets you prepend characters (like comment markers) to multiple lines simultaneously.
:g/pattern/command
The :g/pattern/command (global) command executes an Ex command on every line in the file that matches the given pattern.
<C-o> (in insert mode)
Pressing while in insert mode drops you into a special "insert-normal" mode where you can execute exactly one normal mode command, then immediately return to in
<C-v>jjI\=printf('%02d ', line('.')-line("'<")+1)<CR><Esc>
By combining visual block insert with Vim's expression register, you can insert dynamically computed line numbers at the start of each selected line.
visual-mode #visual-mode #block-mode #line-numbers #expression-register
m{A-Z}
Uppercase marks (A-Z) are global marks that remember both the file and the cursor position.
:let @b = @a
The :let @b = @a command copies the contents of register a into register b.
vis
The is (inner sentence) text object selects the sentence the cursor is in — excluding any leading or trailing whitespace that separates sentences.