How do I run the same command across all windows, buffers, or tabs?
:windo / :bufdo / :tabdo {command}
Vim's do commands iterate over collections and execute a command in each context.
category:
buffers-windows
tags:
#buffers
#windows
#tabs
#batch-editing
#ex-commands
How do I pass a range of lines through a shell command and replace them?
The :{range}!command syntax pipes the specified lines through an external shell command and replaces them with the output.
category:
command-line
tags:
#command-line
#shell
#filtering
#unix
#ex-commands
How do I apply a macro across multiple files at once?
:argdo normal @q | update
The :argdo command runs a command in every file in the argument list.
category:
macros
tags:
#macros
#batch-editing
#multi-file
#ex-commands
#workflow
How do I prevent a macro from stopping when a command fails?
Use :s/pat/rep/e flag or :silent! prefix
By default, Vim macros abort on the first error — a failed search, a substitute with no matches, or a movement that can't be performed.
category:
macros
tags:
#macros
#error-handling
#ex-commands
#batch-editing
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 sort lines and remove duplicates in Vim?
The :sort u command sorts all lines in the file and removes duplicate lines in one operation.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#text-manipulation
#sort
How do I repeat my last substitution across the entire file?
The g& command repeats the last substitute command across the entire file.
category:
search
tags:
#search
#substitute
#ex-commands
#repeat
#workflow
How do I quit Vim with a non-zero exit code?
The :cq command quits Vim and returns a non-zero exit code to the calling process.
category:
command-line
tags:
#command-line
#ex-commands
#git
#workflow
How do I use marks to define a range for Ex commands?
Marks can be used as range specifiers in any Ex command.
category:
command-line
tags:
#marks
#command-line
#ex-commands
#ranges
#editing
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 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 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 encrypt a file directly in Vim?
The :X command sets an encryption key for the current file.
category:
command-line
tags:
#command-line
#security
#file-management
#ex-commands
How do I add text to the end of every line in a range?
The :normal command executes normal-mode keystrokes on every line in a range.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
#batch-editing
How do I search and replace only whole word matches, not partial matches?
Wrapping your search pattern in \ word boundary anchors ensures that Vim only matches the exact whole word, preventing accidental replacements inside longer wor
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I search and replace with confirmation for each match?
Adding the c flag to a substitute command makes Vim pause at every match and ask you whether to replace it.
category:
search
tags:
#search
#substitution
#ex-commands
#editing
How do I use expressions in Vim's substitute replacement?
:%s/pattern/\=expression/g
Vim's substitute command supports expression replacements using \= in the replacement string.
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#advanced
How do I revert a file to its state from a specific time ago?
:earlier {time} / :later {time}
Vim's :earlier and :later commands let you navigate the undo history by wall-clock time rather than by individual undo steps.
category:
editing
tags:
#editing
#undo-redo
#ex-commands
#advanced
#productivity
How do I use normal regex syntax in Vim search without escaping everything?
Vim's default regex syntax requires backslashes before most special characters like +, (, ), {, and , which is the opposite of what most developers expect from
category:
search
tags:
#search
#regex
#ex-commands
#productivity
#patterns
How do I search for a pattern across multiple files and navigate the results?
:vimgrep /pattern/ **/*.ext | copen
The :vimgrep command searches for a regex pattern across multiple files and populates the quickfix list with every match.
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
#productivity
#grep