How do I gather all matches from the current file into a location list without moving the cursor?
When you want a searchable list of matches without leaving your current editing context, :lvimgrep is a strong alternative to regular / navigation.
category:
search
tags:
#search
#quickfix
#location-list
#ex-commands
How do I open the current file at a previous Git revision with vim-fugitive?
When you are deep in a refactor, you often need to compare the current buffer with an older version of the same file.
category:
plugins
tags:
#plugins
#git
#fugitive
#buffers
#history
How do I remove accidental Enter keystrokes from a recorded macro?
:let @q = substitute(@q, '\n', '', 'g')
A common macro failure mode is accidentally hitting while recording.
category:
macros
tags:
#macros
#registers
#debugging
#vimscript
How do I jump to the last line of a file in Vim?
The G command moves the cursor to the last line of the file.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I limit a search or substitution to only the text I visually selected?
The \%V atom in a Vim pattern matches only inside the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#regex
#text-objects
How do I run a literal project-wide vimgrep for the word under my cursor?
:vimgrep /\V<C-r><C-w>/gj **/*
When you need a project-wide search for the exact word under your cursor, this pattern avoids regex surprises and immediately populates quickfix.
category:
search
tags:
#search
#quickfix
#command-line
#project-workflow
How do I insert text at the very first column of a line, ignoring indentation?
Most Vim users know I to insert at the start of a line — but I actually jumps to the first non-blank character, skipping leading whitespace.
category:
editing
tags:
#editing
#insert-mode
#normal-mode
#indentation
How do I create a macro that repeats itself automatically until it can no longer proceed?
A recursive macro ends by calling itself, so it loops automatically without you pressing @q repeatedly.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I create a self-referential recursive macro that repeats until it fails?
A recursive macro in Vim calls itself at the end of its body, repeating automatically until one of its commands fails.
category:
macros
tags:
#macros
#registers
#advanced
#normal-mode
How do I make a key mapping fire immediately without waiting for longer mappings to time out?
nnoremap <nowait> {key} {action}
The flag on a mapping tells Vim not to delay waiting for a longer key sequence.
category:
config
tags:
#config
#normal-mode
#macros
How do I execute a single normal mode command without leaving insert mode?
Pressing in insert mode lets you execute one normal mode command and then automatically returns you to insert mode.
category:
editing
tags:
#editing
#insert-mode
#normal-mode
#productivity
How do I match a pattern but only highlight or capture part of it using \zs and \ze?
How it works Vim's \zs (set start) and \ze (set end) atoms let you define which portion of a pattern counts as the actual match, even though the full pattern is
category:
search
tags:
#search
#ex-commands
#normal-mode
How do I list all lines matching a pattern across the current file and its includes?
The :ilist command searches for a pattern not only in the current buffer but also in files referenced by #include directives (or whatever 'include' is set to).
category:
search
tags:
#search
#ex-commands
#navigation
#editing
How do I search for text that appears after or before a specific pattern without including the pattern in the match?
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
category:
search
tags:
#search
#regex
#advanced-search
#lookahead
#lookbehind
How do I step through a Vimscript command or function to debug it interactively?
The :debug command prefix puts Vim into its built-in interactive debugger before executing the given command.
category:
command-line
tags:
#ex-commands
#debugging
#command-line
#vimscript
How do I sort lines using only the text under a visual column?
When you need to sort records by a substring that starts at a visual column, Vim can do it without external tools.
category:
visual-mode
tags:
#visual-mode
#sorting
#ex-commands
#text-processing
How do I quickly jump between function definitions or top-level blocks in a source file?
The [[ and ]] commands navigate between top-level code blocks — specifically, lines where { appears in column 1.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I do a case-preserving search and replace in Vim?
:%s/\v(old)/\=toupper(submatch(0)[0]).tolower(submatch(0)[1:])/g
Standard substitutions don't preserve the original case of matched text.
category:
search
tags:
#search
#substitute
#case
#text-transformation
How do I zero-pad or reformat numbers during a substitution using printf in Vim?
:%s/\d\+/\=printf('%03d', submatch(0))/g
Combining Vim's \= expression substitution with the printf() function lets you apply arbitrary formatting to matched text.
category:
search
tags:
#search
#substitution
#ex-commands
#editing
How do I suppress the 'Pattern not found' error when a substitution has no match?
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
category:
search
tags:
#search
#substitute
#ex-commands
#macros
#editing