How do I use a Vimscript expression to compute the replacement text in a substitution?
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
category:
command-line
tags:
#search
#ex-commands
#editing
#command-line
How do I open a file and jump directly to a specific line or pattern?
The :edit command accepts a +{cmd} prefix that executes an Ex command immediately after the file is loaded.
category:
command-line
tags:
#buffers
#ex-commands
#navigation
#command-line
How do I search for a pattern across all files in my project with Vim's built-in grep?
:vimgrep /pattern/ (shortened to :vim) is Vim's built-in project-wide search.
category:
command-line
tags:
#search
#ex-commands
#navigation
#command-line
How do I open a related file with a different extension using the current filename?
In Vim's command line, % expands to the current buffer's filename.
category:
command-line
tags:
#ex-commands
#command-line
#buffers
#navigation
How do I insert the full WORD under the cursor (including slashes and dots) into the command line?
When you are in command-line mode, inserts the word under the cursor (alphanumeric and _ only).
category:
command-line
tags:
#command-line
#editing
#registers
How do I view my complete Vim command and search history?
:history displays a numbered list of your recently entered Ex commands, giving you a full audit of what you have run in the current session (and across sessions
category:
command-line
tags:
#ex-commands
#command-line
#search
How do I run a substitution or command on every line in the quickfix list?
:cdo {cmd} executes {cmd} on each entry in the quickfix list — one by one, jumping to each location in turn.
category:
command-line
tags:
#ex-commands
#quickfix
#search
#editing
#buffers
How do I sort lines based on a specific field or column rather than the beginning of each line?
The :sort /pattern/ command sorts lines by the text that appears after the first match of a pattern, not from the start of each line.
category:
command-line
tags:
#ex-commands
#editing
#visual-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 replace a line (or range) with the output of a shell command in Vim?
:.
category:
command-line
tags:
#ex-commands
#editing
#command-line
How do I extract the directory, filename, or extension from the current file path inside a Vim command?
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
category:
command-line
tags:
#ex-commands
#command-line
#editing
How do I run a command on every individual quickfix entry in Vim?
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
category:
command-line
tags:
#command-line
#ex-commands
#search
#editing
How do I run a Vim command without triggering any autocommands?
The :noautocmd modifier (abbreviated :noa) runs any subsequent Ex command while temporarily disabling all autocommand events.
category:
command-line
tags:
#ex-commands
#editing
#config
How do I run a substitute command without overwriting my current search pattern?
Normally, any command that uses a pattern — including :substitute, :global, and :vimgrep — replaces the current search register @/ with the new pattern.
category:
command-line
tags:
#search
#ex-commands
#editing
#command-line
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 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 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