How do I normalize curly quotes to straight quotes in the current buffer?
:%s/[“”]/"/ge<CR>:%s/[‘’]/'/ge<CR>
When text comes from docs, email, or CMS exports, it often contains typographic quotes (“”‘’) that break code snippets, Markdown tooling, or shell comma
category:
editing
tags:
#editing
#substitute
#formatting
#text-cleanup
How do I collapse long runs of blank lines to a single empty line?
When files pass through formatters, generators, or repeated edits, they often accumulate noisy vertical gaps.
category:
editing
tags:
#editing
#substitute
#formatting
#cleanup
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 convert all numbers to fixed-width zero-padded values in Vim?
:%s/\v\d+/\=printf('%04d', submatch(0))/g
When you need aligned numeric data for logs, IDs, or generated fixtures, manual edits are slow and error-prone.
category:
command-line
tags:
#command-line
#substitute
#regex
#formatting
How do I trim trailing whitespace while preserving marks, jumplist, and search state?
:lockmarks keepjumps keeppatterns %s/\s\+$//e
Bulk cleanup commands are easy to automate, but many implementations quietly damage editor state by moving marks, polluting the jumplist, or replacing your last
category:
command-line
tags:
#command-line
#substitute
#automation
#editing
How do I preview substitute changes inline while typing without opening a split?
When you are crafting a risky :substitute command, the expensive part is usually confidence, not typing.
category:
config
tags:
#config
#substitute
#search
#ex-commands
How do I collapse consecutive duplicate words across a file?
:%s/\v<(\w+)\s+\1>/\1/g\<CR>
OCR cleanup, copy-paste artifacts, and rushed note-taking often produce repeated words like the the or is is.
category:
search
tags:
#search
#regex
#substitute
#ex-commands
How do I run an interactive replacement across quickfix entries and only save changed files?
:cdo keeppatterns s/\<foo\>/bar/gec | update
When quickfix already contains precise targets, :cdo gives you a safer multi-file replace loop than broad project substitutions.
category:
command-line
tags:
#command-line
#quickfix
#substitute
#refactoring
How do I zero-pad issue numbers without changing the # prefix?
:%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.
category:
editing
tags:
#editing
#ex-commands
#substitute
#regex
#text-processing
How do I align key=value pairs on one line using a substitute expression in Vim?
:s/\v(\S+)\s*=\s*(.*)/\=printf('%-20s = %s', submatch(1), submatch(2))/
When a line contains uneven key = value spacing, quick manual fixes are easy to get wrong.
category:
editing
tags:
#editing
#substitute
#regex
#formatting
How do I restrict a substitute command to only the text within my last visual selection using the percent-V atom?
The \%V atom in Vim's regex engine matches only within the area of the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#advanced
#ex-commands
How do I remove duplicate consecutive lines using a substitute command?
This substitute command detects pairs of identical adjacent lines and collapses them into one, using a back-reference to match the repeated content.
category:
search
tags:
#search
#substitute
#regex
#editing
#duplicate-lines
How do I swap two adjacent words on a line using a substitute command in Vim?
:s/\v(\w+)\s+(\w+)/\2 \1/
By using capture groups in a substitute command with very magic mode (\v), you can swap two adjacent words in a single operation.
category:
search
tags:
#search
#editing
#substitute
#regex
#text-objects
How do I insert an actual newline in a substitution replacement, and why does backslash-n not work?
In Vim substitutions, \r in the replacement string inserts a line break, creating a new line.
category:
editing
tags:
#editing
#search
#substitute
#newline
#regex
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 transform matched text to uppercase or lowercase directly inside a substitute replacement?
Vim's :substitute command supports case-transformation escape sequences in the replacement string.
category:
search
tags:
#search
#substitute
#ex-commands
#editing
#text-objects
How do I suppress the 'Pattern not found' error when a substitution has no match?
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
category:
search
tags:
#search
#substitute
#ex-commands
#macros
#editing
How do I make substitutions replace every match on a line by default without typing the g flag?
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.
category:
config
tags:
#config
#search
#substitute
#ex-commands
How do I change the case of matched text in a substitute replacement using \u, \U, \l, or \L modifiers?
Vim's substitute command supports case-change modifiers in the replacement string that let you capitalize, uppercase, or lowercase matched text as part of the s
category:
search
tags:
#search
#ex-commands
#substitute
#editing
How do I count the number of lines containing a pattern without making any replacements?
The n flag in the substitute command suppresses the actual replacement and instead reports the match count.
category:
search
tags:
#search
#ex-commands
#substitute
#normal-mode