How do I zero-pad every number in a buffer using one substitute expression?
:%s/\d\+/\=printf('%04d', submatch(0))/g
When you need fixed-width numeric fields, manually editing each number is slow and error-prone.
:%s/\d\+/\=printf('%04d', submatch(0))/g
When you need fixed-width numeric fields, manually editing each number is slow and error-prone.
:lvimgrep /pattern/j %
When you want a searchable list of matches without leaving your current editing context, :lvimgrep is a strong alternative to regular / navigation.
:%s/\V<C-r>//gc
When your last search pattern contains punctuation, slashes, or regex atoms, retyping it inside :substitute is error-prone.
:'<,'>s/^/\=line('.')-line("'<")+1 . '. '/
When you need quick numbered steps, logs, or checklist entries, this pattern adds numbers only to the lines you selected, not the whole buffer.
:packadd cfilter | Cfilter /ERROR/
Quickfix lists can get noisy in large projects, especially when one grep or compiler run mixes several classes of issues.
:put =getreg('a', 1, 1)
Most register pastes are character-oriented, but advanced edits often need to preserve exact line structure.
registers #registers #ex-commands #scripting #text-processing
:'<,'>normal @@
When you already have a useful macro but need to apply it to a specific block of lines, :'normal @@ is a high-leverage pattern.
:vimgrepadd /FIXME/j **/*.go
When you are triaging a codebase, one pattern is rarely enough.
:bufdo if &buftype ==# '' | update | endif
bufdo is powerful for multi-buffer automation, but a naive write pass can error on special buffers (help, terminal, quickfix, prompts).
buffers-windows #buffers #windows #ex-commands #automation #workflow
:cdo normal! @q
When a refactor target spans many files but only specific matches matter, running a macro globally is risky.
:'<,'>sort /\%V.*$/
When you need to sort records by a substring that starts at a visual column, Vim can do it without external tools.
visual-mode #visual-mode #sorting #ex-commands #text-processing
:history :
When you work with long substitution pipelines or multi-part Ex commands, digging through all history (:history) adds noise.
:wn
:wn (short for :wnext) writes the current buffer to disk and immediately advances to the next file in the argument list.
:set shada
Neovim's ShaDa (Shared Data) file replaces Vim's viminfo and persists session state across restarts — marks, registers, command history, search history, jump
:g/BEGIN/+1,/END/-1 delete
By combining the :global command with a relative address range, you can delete the content between repeating delimiter pairs while leaving the delimiters intact
:s#pattern#replacement#g
Vim's substitution command accepts any non-alphanumeric, non-whitespace character as the delimiter — not just /.
:set makeprg=
The makeprg option defines the command that :make runs.
let {var} =<< {marker}
Vim 8.
:try / :catch / :endtry
Vimscript has a structured exception handling system using :try, :catch, :finally, and :endtry.
function! {name}#{funcname}() in autoload/{name}.vim
Vim's autoload mechanism lets you place functions in autoload/*.