How do I zero-pad every number in a line using a Vim substitute expression?
:s/\v\d+/\=printf('%04d', submatch(0))/g
Substitution expressions let Vim compute each replacement dynamically, which is ideal when plain capture groups are too limited.
:s/\v\d+/\=printf('%04d', submatch(0))/g
Substitution expressions let Vim compute each replacement dynamically, which is ideal when plain capture groups are too limited.
gUip
gUip is a compact operator-plus-text-object pattern that uppercases exactly the paragraph your cursor is in.
g~ap
g~ap is a fast way to invert letter case across a full paragraph without entering Visual mode.
editing #editing #operators #text-objects #case #normal-mode
dv{motion}
In operator-pending mode — after typing an operator like d, y, or c but before the motion — you can press v, V, or to override the motion type to characterw
y/{pattern}<CR>
Any operator in Vim can take a search motion as its argument.
:set noexpandtab | retab!
When you inherit space-indented code and need to switch to tabs, :retab! (with the bang) converts groups of spaces into tabs throughout the file.
as and is
Vim defines sentence text objects — as (around sentence) and is (inner sentence) — that allow any operator to act on an entire sentence in one motion.
<C-k>{two-chars}
Vim's digraph system lets you type hundreds of special characters — arrows, fractions, accented letters, currency symbols, and more — using intuitive two-ch
!{motion}sort
The ! operator in Vim filters a motion's text through an external shell command, replacing it with the output.
iW vs iw
Vim has two flavors of the "inner word" text object that are easy to confuse: iw (lowercase) and iW (uppercase).
gr{motion}
Neovim 0.
dgn
The gn motion is a versatile text object that selects the next occurrence of the last search pattern.
editing #editing #search #text-objects #normal-mode #motions
g??
Vim has a built-in ROT13 operator g? that encodes text by rotating each letter 13 positions in the alphabet.
:put =''
Using :put ='' with an empty expression lets you insert blank lines in normal mode without ever entering insert mode.
editing #editing #normal-mode #ex-commands #expression-register #blank-line
<C-x><C-n>
triggers keyword completion that searches only the current buffer for matches, scanning forward from the cursor.
dV{motion}
In operator-pending mode — the brief state after typing an operator like d, c, or y but before entering the motion — you can prefix the motion with v, V, or
zr
zr ("reduce" fold level) decrements the global foldlevel option by 1, opening the next layer of folds across the entire file.
>%
Vim's > operator (indent) works with any motion or text object — including %, which jumps to the bracket, parenthesis, or brace matching the one under the cur
editing #editing #indentation #text-objects #normal-mode #motions
>G
The >G command applies a right-indent shift to every line from the cursor through the last line of the buffer.
{count}r{char}
The {count}r{char} command replaces a precise number of characters starting at the cursor position with a single repeated character.