139 results for
"S substitute line"
How do I use a Vim expression to dynamically compute the replacement in a substitution?
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
category:
registers
tags:
#search
#editing
#ex-commands
#registers
How do I remove Windows carriage returns (^M) from a file opened in Vim?
When a file created on Windows is opened in Vim on a Unix system, lines may retain \r (carriage return) characters, displayed as ^M at the end of each line.
category:
editing
tags:
#editing
#search
#ex-commands
#normal-mode
How do I quickly delete all lines in the current buffer?
The % range address in Ex commands stands for the entire file — it is shorthand for 1,$ (first line to last line).
category:
command-line
tags:
#ex-commands
#editing
#command-line
How do I paste the contents of a register into the command line or search prompt?
When typing an Ex command or search pattern, you often need to insert text you've already yanked or deleted.
category:
registers
tags:
#registers
#command-line
#search
#editing
What is the difference between \n and \r in Vim search patterns versus substitution replacements?
\n in search, \r in replacement
Vim uses \n and \r differently depending on whether they appear in a search pattern or a replacement string, and mixing them up is a common source of confusion.
category:
search
tags:
#search
#substitution
#newline
#patterns
#editing
How do I duplicate every line matching a pattern, placing a copy directly below each one?
Combining :global with the :t (copy) command and the .
category:
command-line
tags:
#editing
#ex-commands
#search
#command-line
How do I run a dynamically constructed Ex command or pass special keys to :normal?
:execute evaluates a string as an Ex command, letting you build commands dynamically or embed special key sequences (like or ) as literal characters.
category:
command-line
tags:
#ex-commands
#command-line
#macros
#config
How do I rename a variable across all its case variants (camelCase, snake_case, SCREAMING_CASE) in one command?
vim-abolish provides :Subvert, a smarter substitute that detects and preserves the case style of each match.
category:
plugins
tags:
#editing
#search
#ex-commands
How do I insert a newline in the replacement string of a :s substitution?
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I write a Vim search pattern that matches text spanning multiple lines?
Vim's regex engine normally treats .
category:
search
tags:
#search
#regex
#normal-mode
How do I execute a command without changing '[ and '] marks in Vim?
Many batch edits in Vim update special marks like '[ and '], which can disrupt follow-up motions or tooling that depends on those positions.
category:
navigation
tags:
#navigation
#marks
#command-line
#refactoring
#editing
How do I delete all blocks of text between two patterns throughout a file?
The :g (global) command can operate on ranges, not just single lines.
category:
search
tags:
#search
#editing
#ex-commands
How do I search for a pattern only on a specific line number or at a specific column position?
Vim's \%l and \%c pattern atoms anchor a search to a particular line number or column, enabling surgical searches and substitutions that standard regex cannot e
category:
search
tags:
#search
#regex
#ex-commands
How do I collapse multiple consecutive spaces into a single space throughout a file?
The pattern \s\+ matches one or more whitespace characters (spaces, tabs).
category:
editing
tags:
#editing
#search
#ex-commands
How do I run a substitution over every quickfix hit and save only changed files?
:cdo s/foo/bar/ge | update
When quickfix already contains exactly the lines you want to touch, :cdo is the safest way to batch-edit with tight scope.
category:
command-line
tags:
#command-line
#quickfix
#substitution
#refactoring
How do I use capture groups in Vim substitutions to rearrange or swap matched text?
Vim's substitute command supports capture groups using \( and \) (or ( and ) in \v very-magic mode).
category:
search
tags:
#search
#editing
#substitution
#regex
#ex-commands
How do I run a command without moving the cursor or changing the scroll position?
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
category:
command-line
tags:
#ex-commands
#editing
#vimscript
#navigation
How do I load yanked text into search as a literal pattern without regex escaping headaches?
:let @/='\V'.escape(@", '\\')
When you yank text that contains regex characters like .
category:
search
tags:
#search
#registers
#regex
#command-line
How do I run a command on every line that does NOT match a pattern?
:v (short for :vglobal) is the inverse of :g.
category:
command-line
tags:
#ex-commands
#command-line
#editing
How do I run a global command only on lines that match two different patterns simultaneously?
:g/pattern1/g/pattern2/command
Vim's :g command can be nested — the command part of one :g can itself be another :g.
category:
command-line
tags:
#ex-commands
#search
#editing
#command-line