How do I pipe a range of lines through an external command and replace them with the output?
The ! operator filters the text covered by a motion through an external shell command, replacing the original lines with the command's stdout.
category:
editing
tags:
#editing
#ex-commands
#normal-mode
#formatting
How do I count how many times a pattern appears in a file without making any changes?
The n flag on the substitute command reports the number of matches without performing any substitution.
category:
search
tags:
#search
#substitute
#ex-commands
#normal-mode
How do I run a substitute command without overwriting my last search pattern?
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
category:
command-line
tags:
#search
#ex-commands
#command-line
#substitute
#registers
How do I apply a normal mode command to every line in a range at once?
:normal (abbreviated :norm) executes a sequence of normal-mode keystrokes on each line of an address range.
category:
command-line
tags:
#ex-commands
#editing
#normal-mode
#macros
How do I copy lines to a different location in the file without overwriting my yank register?
The :t command (short for :copy) copies addressed lines to a destination line number, leaving the unnamed register untouched.
category:
command-line
tags:
#ex-commands
#editing
#normal-mode
#registers
How do I run a recorded macro across multiple files at once?
Combining :argdo with :norm @a lets you apply a recorded macro to every file in Vim's argument list — a powerful pattern for bulk refactoring across a project
category:
macros
tags:
#macros
#ex-commands
#editing
#buffers
How do I filter the entire buffer (or a range of lines) through an external shell command?
The ! operator pipes text through a shell command, replacing the selected lines with the command's output.
category:
command-line
tags:
#ex-commands
#editing
#command-line
How do I count how many times a pattern appears in a file without making any changes?
The n flag on the substitute command makes it report the match count without actually performing any replacement.
category:
search
tags:
#search
#ex-commands
#editing
How do I sort lines and remove duplicates in one command?
The :sort u command sorts all lines in the buffer (or a selected range) alphabetically and removes duplicate lines in a single pass.
category:
editing
tags:
#editing
#ex-commands
#formatting
How do I define or fix a macro using Vimscript instead of re-recording it?
Macros in Vim are just text stored in named registers.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I insert the result of a Vim expression or calculation directly into text?
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
category:
registers
tags:
#registers
#insert-mode
#editing
#ex-commands
How do I run a substitution without overwriting my current search pattern?
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
category:
command-line
tags:
#ex-commands
#search
#substitution
#command-line
#scripting
How do I save all modified buffers at once without switching to each one?
When working across multiple files, you often have unsaved changes in several buffers.
category:
command-line
tags:
#buffers
#ex-commands
#editing
How do I create a macro by typing it out instead of recording it interactively?
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
category:
macros
tags:
#macros
#registers
#ex-commands
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 sort lines by a specific column or field in Vim?
Vim does not have a built-in multi-column sort, but you can leverage the external sort command to sort selected lines by any field.
category:
editing
tags:
#editing
#sorting
#ex-commands
#external-commands
#command-line
How do I search for a pattern across all files in a project using Vim's built-in grep?
While external tools like grep or ripgrep are fast, Vim's built-in :vimgrep has a key advantage: it populates the quickfix list directly, so you can jump betwee
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
How do I find out which scripts or plugins are slowing down my Vim startup?
When Vim feels sluggish to start, the built-in :profile command lets you measure exactly how much time each script, function, or plugin takes to load.
category:
config
tags:
#config
#performance
#debugging
#ex-commands
How do I run the same command across all open buffers at once?
When you need to apply the same change to every file you have open in Vim, switching to each buffer manually is tedious and error-prone.
category:
buffers-windows
tags:
#buffers
#ex-commands
#editing
#batch
How do I control exactly where a new split window appears in Vim?
By default, Vim places horizontal splits below and vertical splits to the right (controlled by splitbelow and splitright).
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
#splits