How do I join every line matching a pattern with the line that follows it?
The :g/pattern/join command combines the :global command with :join to merge every line matching a pattern with the line immediately following it.
category:
command-line
tags:
#ex-commands
#editing
#command-line
#search
#normal-mode
How do I delete text from the cursor to the next occurrence of a pattern?
Vim lets you use a / search as a motion for any operator.
category:
editing
tags:
#editing
#search
#motions
#delete
#normal-mode
How do I search for a pattern only within a specific range of lines in Vim?
:/start/,/end/s/pattern/replacement/g
You can restrict a substitution to a range defined by two patterns.
category:
search
tags:
#search
#ex-commands
#editing
#substitution
How do I run a macro on every line matching a pattern?
The :global command combined with :normal lets you execute a recorded macro on every line that matches a given pattern.
category:
macros
tags:
#macros
#command-line
#ex-commands
#global
#batch-editing
How do I count the number of matches for a search pattern?
The :%s/pattern//gn command counts how many times a pattern appears in the file without making any changes.
category:
search
tags:
#search
#ex-commands
#editing
How do I search for a pattern repeated an exact number of times in Vim?
Vim supports counted quantifiers that let you specify exactly how many times a pattern should repeat.
category:
search
tags:
#search
#regex
#quantifiers
#patterns
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 insert a new line of text after every line matching a pattern using the global command?
Combining :global with :put = lets you insert synthesized lines of content after every line matching a pattern — without plugins or complex macros.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#global
How do I move all lines matching a pattern to the end of a file?
The :g (global) command combined with :m (move) relocates all matching lines to a specified destination.
category:
command-line
tags:
#command-line
#ex-commands
#global
#editing
#organization
How do I collect all lines matching a pattern into a register?
The :g/pattern/y A command yanks every line matching the pattern and appends it to register a.
category:
command-line
tags:
#command-line
#registers
#global
#ex-commands
#filtering
How do I copy all lines matching a pattern to the end of the file?
How it works The :g (global) command combined with :t (copy) lets you duplicate all lines matching a pattern to a specific location.
category:
search
tags:
#search
#editing
#ex-commands
How do I view or manipulate the search pattern register in Vim?
The / register holds the most recent search pattern.
category:
registers
tags:
#registers
#search
#pattern
#special-registers
How do I open a file and automatically jump to the first line matching a pattern?
The +{cmd} flag on :edit (and most file-opening commands) runs an Ex command immediately after the file loads.
category:
command-line
tags:
#command-line
#ex-commands
#navigation
#search
#buffers
How do I temporarily highlight a custom text pattern in my buffer without changing the syntax file?
:match {group} /{pattern}/
:match lets you apply a highlight group to any pattern in the current window without touching the buffer or its syntax rules.
category:
config
tags:
#search
#config
#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 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
How do I count the number of pattern matches in a file without making substitutions?
The :s///gn command counts how many times a pattern appears in the file without actually replacing anything.
category:
command-line
tags:
#search
#ex-commands
#substitution
#command-line
How do I chain multiple commands on lines matching a pattern with :g?
The :g (global) command can execute multiple Ex commands per matching line by chaining them with .
category:
command-line
tags:
#command-line
#global
#ex-commands
#batch-editing
#advanced
How do I comment out all lines matching a pattern at once using vim-commentary?
vim-commentary exposes Commentary as an Ex command that toggles comments on the current line, making it composable with Vim's :global command.
category:
plugins
tags:
#plugins
#vim-commentary
#ex-commands
#editing
How do I filter the quickfix list to only show entries matching a pattern?
Vim ships with an optional built-in package called cfilter that adds :Cfilter and :Lfilter commands for narrowing down quickfix and location list entries by pat
category:
command-line
tags:
#ex-commands
#quickfix
#search
#command-line