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 run a normal mode command on every line matching a pattern?
Combining :global with :normal lets you run any normal-mode keystrokes on every line that matches a pattern.
category:
editing
tags:
#editing
#ex-commands
#normal-mode
#macros
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 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 run a substitution only within the exact columns of a visual selection, not the whole line?
:'<,'>s/\%Vpattern/replacement/g
When you press : after making a visual selection, Vim inserts ' to restrict the substitution to the selected lines.
category:
visual-mode
tags:
#visual-mode
#search
#editing
#ex-commands
#normal-mode
How do I override ignorecase or smartcase for a single search without changing my settings?
Vim's \c and \C flags let you force a search to be case-insensitive or case-sensitive on a per-search basis, regardless of your ignorecase and smartcase setting
category:
search
tags:
#search
#normal-mode
#ex-commands
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 capture shell command output directly into a Vim register?
You can populate any Vim register with the output of an external shell command using :let @{register} = system('{command}').
category:
registers
tags:
#registers
#ex-commands
#shell
How do I define or modify a macro directly as a string without recording it?
Macros in Vim are stored in registers as plain text.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
How do I run a substitution only within the exact characters of my visual selection?
:%s/\%Vpattern/replacement/g
The \%V atom restricts a regex match to the last visual selection — more precisely than :'s/.
category:
search
tags:
#search
#visual-mode
#ex-commands
#normal-mode
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 change the working directory for only the current window without affecting other windows or tabs?
:cd changes the global working directory, affecting every window and tab in the session.
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
#navigation
How do I open a split window that spans the full width or height of the editor instead of splitting only the current window?
When you split a window with :split or :vsplit, Vim subdivides only the current window.
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
#command-line
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 set a different working directory for each split window in Vim?
:lcd (local cd) sets the working directory for the current window only, leaving other windows at their previous directory.
category:
buffers-windows
tags:
#buffers-windows
#navigation
#ex-commands
#config
How do I use a VimScript expression as the replacement in a substitution?
:s/pattern/\=expression/g
Prefixing the replacement string with \= in a :substitute command tells Vim to evaluate the rest as a VimScript expression rather than literal text.
category:
search
tags:
#search
#ex-commands
#editing
#normal-mode
How do I programmatically combine or modify the contents of Vim registers?
You can manipulate register contents directly using the :let command with the @{reg} syntax.
category:
registers
tags:
#registers
#editing
#normal-mode
#ex-commands
How do I see a list of recently opened files and quickly jump back to one?
:oldfiles displays a numbered list of every file Vim has recorded in its viminfo (or shada in Neovim) file.
category:
navigation
tags:
#navigation
#buffers
#ex-commands
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 apply a recorded macro to every line in a visual selection?
Combining :normal with a visual range lets you replay a macro on each line of a selection individually — far more targeted than recursive macros or @@ repeati
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#visual-mode