How do I restrict a search to a specific line-number window without selecting text first?
Vim's search engine can constrain matches by line number, which is useful when you want to scan a known section without touching the rest of the buffer.
category:
search
tags:
#search
#patterns
#regex
#navigation
#advanced
How do I open another file without changing the alternate-file mark (#)?
The alternate-file mark (#) powers fast toggles like and commands that depend on the previous file context.
category:
command-line
tags:
#command-line
#buffers
#workflow
#navigation
#advanced
How do I clear undo history for the current buffer in Vim?
:let s:u=&l:undolevels | setlocal undolevels=-1 | execute "normal! a\<BS>\<Esc>" | let &l:undolevels=s:u
Sometimes you finish a risky refactor and want a clean undo boundary before handing the buffer off or continuing with unrelated edits.
category:
config
tags:
#undo-redo
#config
#command-line
#advanced
How do I mix very-nomagic and magic sections in a single Vim search?
Sometimes you need one search pattern that treats a literal path strictly while still using regex power for the suffix.
category:
search
tags:
#search
#regex
#pattern
#advanced
How do I copy one register to another while preserving its exact register type?
:call setreg('b', getreg('a'), getregtype('a'))
Plain register copies like :let @b = @a move text, but they can lose important metadata about register type.
category:
registers
tags:
#registers
#advanced
#vimscript
#editing
How do I search only a sub-part of a larger pattern using \zs and \ze?
Sometimes you need Vim to match a long structural pattern but only treat one piece of it as the actual match.
category:
search
tags:
#search
#regex
#pattern-matching
#advanced
How do I restrict a substitute command to only the text within my last visual selection using the percent-V atom?
The \%V atom in Vim's regex engine matches only within the area of the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#advanced
#ex-commands
How do I match text only when it is followed by a specific pattern using zero-width lookahead?
Vim's regex engine supports zero-width positive lookahead via the \@= operator.
category:
search
tags:
#search
#regex
#lookahead
#advanced
#pattern
How do I execute Lua code directly from the Neovim command line without writing a script file?
Neovim's :lua command lets you run arbitrary Lua code inline from the command line.
category:
command-line
tags:
#command-line
#lua
#neovim
#vimscript
#advanced
How do I write a Vim regex that matches any character including newlines for multi-line pattern matching?
In Vim's regular expressions, .
category:
search
tags:
#search
#regex
#multiline
#advanced
#pattern
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 jump directly to a specific point in the undo history by change number?
:undo {N} lets you jump directly to the undo tree state after change number N was applied.
category:
editing
tags:
#undo-redo
#editing
#advanced
How do I apply a recorded macro to a range of lines without re-recording it in Vim?
The :[range]normal @a command runs a recorded macro against every line in a given range.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
#advanced
How do I configure Vim's :grep command to use ripgrep for faster project-wide searching?
:set grepprg=rg\ --vimgrep\ --smart-case
By default, Vim's :grep command calls the system grep.
category:
config
tags:
#search
#ex-commands
#config
#quickfix
#advanced
How do I prepend a value to the beginning of a comma-separated Vim option like path or wildignore?
Vim's :set option^=value operator prepends a value to the front of a list-style option, giving it the highest priority.
category:
config
tags:
#config
#ex-commands
#settings
#advanced
How do I move the cursor in insert mode without creating an undo break point?
By default, moving the cursor with arrow keys while in insert mode creates an undo break — meaning a subsequent u will undo only back to when you last moved,
category:
editing
tags:
#insert-mode
#undo-redo
#editing
#advanced
How do I match text only when it is preceded by a specific pattern in Vim regex?
:%s/\(prefix\)\@<=target/replacement/g
Vim's \@<= is a zero-width look-behind assertion.
category:
search
tags:
#search
#regex
#substitution
#advanced
How do I use \zs and \ze to define the exact boundaries of a regex match in Vim?
Vim's \zs ("match start") and \ze ("match end") atoms let you narrow the actual match region within a broader pattern context.
category:
search
tags:
#search
#regex
#substitution
#patterns
#advanced
How do I group part of a Vim regex pattern without creating a numbered capture group?
Vim's standard grouping syntax \(.
category:
search
tags:
#search
#patterns
#regex
#advanced
How do I match a pattern only when preceded or followed by another pattern using zero-width assertions?
Vim's regex engine supports zero-width lookahead and lookbehind assertions — \@= and \@<= — which let you match text based on surrounding context without in
category:
search
tags:
#search
#regex
#advanced
#patterns
#substitution