How do I use case modifiers like \u and \U in a substitution replacement to change capitalization?
Vim's substitute command supports case-modifier escapes in the replacement string: \u uppercases the next character, \U uppercases all text until \E or end of r
category:
search
tags:
#search
#editing
#substitute
#regex
#ex-commands
How do I zero-pad numbers with :substitute using an expression replacement?
:%s/\v(\d+)/\=printf('%04d', submatch(1))/g<CR>
When you need to normalize IDs, ticket numbers, or sequence values, :substitute can do more than plain text replacement.
category:
command-line
tags:
#command-line
#substitute
#regex
#formatting
#ex-commands
How do I choose between multiple tag definitions when jumping to a symbol in Vim?
When a symbol (function, class, variable) is defined in multiple places, CTRL-] blindly jumps to the first match.
category:
navigation
tags:
#navigation
#tags
#normal-mode
How do I jump to a tag in a new split window showing all matching tags?
g] splits the window and then runs :tselect for the identifier under the cursor, displaying a numbered list of all matching tags so you can pick the exact defin
category:
buffers-windows
tags:
#navigation
#buffers
#windows
#tags
How do I collect all lines matching a pattern into a register without leaving them in place?
Using :g/pattern/d A you can sweep through the entire buffer and extract every line that matches a pattern into register a, removing them from the buffer in the
category:
registers
tags:
#registers
#ex-commands
#search
#editing
#global
How do I search and replace only whole words and not partial matches in Vim?
:%s/\<word\>/replacement/g
How it works In Vim's regular expressions, \ are word boundary anchors: \ matches the end of a word.
category:
editing
tags:
#editing
#search
#ex-commands
How do I use a register value as the replacement string in a substitution?
How it works In Vim's substitute command, the replacement string can be a Vimscript expression when prefixed with \=.
category:
registers
tags:
#registers
#search
#ex-commands
#editing
How do I join wrapped paragraph lines while keeping blank-line paragraph separators?
When text is hard-wrapped (for example from email, logs, or copied docs), joining entire paragraphs manually is slow and error-prone.
category:
editing
tags:
#editing
#formatting
#ex-commands
#text-manipulation
How do I replace only part of a matched pattern using \zs and \ze in a substitution?
:%s/\zsparseData\ze(/processData/g
Vim's \zs and \ze atoms let you include context in your search pattern without including that context in the replacement.
category:
search
tags:
#search
#substitution
#regex
#editing
How do I convert text to title case (capitalize first letter, lowercase the rest of each word)?
Vim's substitute command supports case-conversion escape sequences in the replacement string.
category:
search
tags:
#search
#editing
#normal-mode
#ex-commands
How do I replace each match with an incrementing number using a counter variable in Vim?
:let i=0 | g/pattern/s/pattern/\=printf('%d', i+=1)/
By combining :let, the :g global command, and an expression substitution with \=, you can replace every match of a pattern with a unique incrementing number.
category:
search
tags:
#search
#ex-commands
#registers
#editing
How do I search across multiple files and navigate results without leaving Vim?
:vimgrep /pattern/g **/*.ext
The :vimgrep command searches for a pattern across multiple files and loads the results into the quickfix list.
category:
search
tags:
#search
#multi-file
#quickfix
#grep
#workflow
How do I reuse my last search pattern in a substitute command without retyping it?
Leaving the search field empty in a :s command tells Vim to reuse the last search pattern from / or .
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#productivity
How do I restrict a substitution to the range between two named marks?
Named marks can serve as range endpoints for any Ex command, including :substitute.
category:
search
tags:
#search
#marks
#substitution
#ex-commands
#editing
How do I record a macro that performs a search and replace on each line?
How it works You can combine Ex commands like :s (substitute) with macro recording to create powerful repeatable find-and-replace operations that go beyond what
category:
macros
tags:
#macros
#ex-commands
#search
#editing
How do I edit or modify an existing Vim macro programmatically without re-recording it?
:let @q = substitute(@q, "old", "new", "g")
Vim macros are stored as plain text in registers, which means you can inspect and modify them like any other string.
category:
macros
tags:
#macros
#registers
#vimscript
#advanced
#editing
How do I use capture groups to rearrange text in a Vim substitute command?
:%s/\(pattern1\)\(pattern2\)/\2\1/g
Vim's substitute command supports capture groups that let you match parts of text, remember them, and rearrange or reuse them in the replacement.
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I run a :g or :s command without overwriting my current search pattern?
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
category:
search
tags:
#search
#ex-commands
#macros
How do I edit the contents of a macro register without re-recording it?
:let @q = substitute(@q, 'old', 'new', 'g')
When a recorded macro has a typo or needs a small tweak, re-recording the entire thing is error-prone.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I debug a macro by stepping through it command by command?
:let g:debug_macro=1 | normal @a
When a macro doesn't work as expected, debugging it step by step is essential.
category:
macros
tags:
#macros
#debugging
#troubleshooting
#registers