How do I suppress the 'Pattern not found' error when a substitution has no match?
:s/pattern/replacement/e
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
139 results for "S substitute line"
:s/pattern/replacement/e
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
:%s/\n\{3,}/\r\r/g
When files pass through formatters, generators, or repeated edits, they often accumulate noisy vertical gaps.
:%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.
: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
: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.
command-line #command-line #quickfix #substitute #refactoring
:%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.
editing #editing #ex-commands #substitute #regex #text-processing
:%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
:s/^/\=line('.') - line("'<") + 1 . '. '/
When you need to quickly number a set of lines — such as TODO items, steps, or bullet points — you can use a visual selection combined with a substitution e
visual-mode #visual-mode #editing #ex-commands #formatting #substitute
:set gdefault
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.
s/pattern/\r/
In Vim substitutions, \r in the replacement string inserts a line break, creating a new line.
:help topic
Vim has an extensive built-in help system.
:%s/0x\x\+/\=str2nr(submatch(0), 16)/g
When cleaning logs, protocol dumps, or generated code, you may need to normalize 0x.
q/k?pattern<CR>
Vim's command-line history window (q: for Ex commands, q/ for search) opens a full editing buffer containing your history.
:put =toupper(@")
Registers in Vim are not only for raw replay; you can treat them as string data and transform them at paste time.
registers #registers #expression-register #editing #vimscript
:/start/,/end/ {command}
Vim's range addressing lets you specify a line range using search patterns instead of explicit line numbers.
:%s/\n/ /g
Using \n in the pattern of :substitute matches the newline character at the end of each line, letting you join lines with any separator you choose — something
:keeppattern {cmd}
Many Ex commands silently overwrite the search register (@/), which changes your hlsearch highlighting and n/N behavior.
<C-r>/
Vim stores your last search pattern in the / register.
:%s/\(\d\+\)/\=submatch(1)+1/g
Vim's substitute command supports using a VimScript expression as the replacement by prefixing it with \=.
"/p
Vim stores the last search pattern in the search register "/.