How do I run an Ex command without changing the current search pattern?
:keeppattern {cmd}
Many Ex commands silently overwrite the search register (@/), which changes your hlsearch highlighting and n/N behavior.
640 results for "/pattern"
:keeppattern {cmd}
Many Ex commands silently overwrite the search register (@/), which changes your hlsearch highlighting and n/N behavior.
glob()
The glob() built-in function expands a wildcard pattern into a list of matching filesystem paths, entirely within Vimscript.
\%^ and \%$
Vim's ^ and $ anchors match the start and end of a line, but sometimes you need to match the very beginning or very end of the entire buffer.
\%#
The \%# atom in Vim's regex engine matches the exact position of the cursor — zero-width, between characters.
/\%d{decimal}
Vim's regex engine supports special atoms that match characters by their numeric value rather than their glyph.
:g/pattern1/s/pattern2/replacement/g
Combining :g with :s lets you apply a substitution using two independent patterns: :g selects which lines to act on, and :s controls what gets replaced within t
:echo searchcount({'recompute': 1})
Vim can show match counts for your last search, but in large files or after big edits the cached values may lag.
search #search #command-line #automation #statusline #diagnostics
:args **/*.py
Vim's argument list (arglist) is a named list of files that you can operate on as a group.
:set incsearch hlsearch
The combination of incsearch and hlsearch gives you live, interactive search highlighting.
gn
The gn motion searches forward for the next match of the last search pattern and visually selects it.
search #navigation #search #motions #normal-mode #repeat #editing
/\Vsrc/main.c\m:\d\+<CR>
Sometimes you need one search pattern that treats a literal path strictly while still using regex power for the suffix.
/\%>5c\%<20cpattern
How it works Vim's search patterns support column position constraints using the \%c family of atoms.
/\Cpattern
Vim's ignorecase and smartcase settings change how all searches behave globally.
/foo\_.*bar
Vim's default .
/\c
Vim lets you override the ignorecase and smartcase settings on a per-search basis using the \c (case-insensitive) and \C (case-sensitive) atoms directly inside
:/start/,/end/command
Vim allows pattern-based ranges in Ex commands, letting you operate on lines between two search matches.
gN
Most users know gn for selecting the next search match, but its counterpart gN is the real power move when you need to work backward through matches.
visual-mode #visual-mode #search #motions #editing #normal-mode
:g/\(.\+\)\n\1/d
The :g command with a backreference pattern can detect and delete consecutive duplicate lines in one pass.
:s/,/,\r/g
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
:set ignorecase smartcase
How it works By setting both ignorecase and smartcase, Vim uses an intelligent case sensitivity rule for searches: If your search pattern is all lowercase, the