How do I get exact current and total counts for my last search pattern in Vim?
: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.
category:
search
tags:
#search
#command-line
#automation
#statusline
#diagnostics
How do I force a register to be linewise before I put it in Vim?
:call setreg('a', @a, 'V')
When you paste from a register, Vim uses that register's stored type: characterwise, linewise, or blockwise.
category:
registers
tags:
#registers
#editing
#command-line
#setreg
How do I append the current filename to a named register from Ex command-line?
:let @a .= expand('%:t') . "\n"
Named registers are not just for yanks and deletes.
category:
registers
tags:
#registers
#command-line
#automation
#editing
How do I remove trailing whitespace across all open buffers and save only changed files?
:bufdo keeppatterns %s/\s\+$//e | update
If you keep many files open during a refactor, cleaning trailing whitespace one buffer at a time is slow and error-prone.
category:
buffers-windows
tags:
#buffers
#command-line
#editing
#whitespace
How do I search a project without overwriting the global quickfix list?
:lvimgrep /pattern/gj **/*.js | lopen
When you already rely on the global quickfix list for compiler errors or another search, running :vimgrep can wipe that context.
category:
search
tags:
#search
#command-line
#quickfix
#navigation
How do I preview a fuzzy tag match in the preview window without immediately switching buffers?
When a symbol name is ambiguous, jumping directly with :tag can bounce you around the codebase and disrupt your working context.
category:
navigation
tags:
#navigation
#tags
#windows
#code-navigation
#command-line
How do I remove trailing whitespace without clobbering @/ or showing no-match errors?
:silent keeppatterns %s/\s\+$//e
Trailing whitespace cleanup is a common housekeeping step, but a plain substitution can leave side effects: it can overwrite your last search pattern (@/) and t
category:
command-line
tags:
#command-line
#ex-commands
#editing
#search
#formatting
How do I run one substitution in nomagic mode so most regex characters are literal?
:snomagic /foo.\+/bar/<CR>
When a pattern is mostly literal text with just a little regex, default magic mode can force extra escaping and make substitutions harder to read.
category:
command-line
tags:
#command-line
#search
#regex
#editing
How do I trim trailing whitespace in a file without polluting jumplist or search history?
:keepjumps keeppatterns %s/\s\+$//e<CR>
Bulk whitespace cleanup is common, but a plain substitution can leave side effects: your last search pattern changes and jump navigation gets noisy.
category:
editing
tags:
#editing
#command-line
#search
#formatting
How do I preview a macro register with escaped keycodes before executing it?
Macro failures are often caused by hidden control keys like , , or tabs that are hard to see in raw register output.
category:
registers
tags:
#registers
#macros
#debugging
#command-line
How do I run a normal-mode append on only matching lines inside a visual selection?
:'<,'>g/let /normal! A;<CR>
When you need a structural edit in part of a file, Visual mode ranges combine well with :global and :normal!.
category:
visual-mode
tags:
#visual-mode
#command-line
#ex-commands
#editing
How do I rotate split windows forward without reopening any buffers?
When a split layout is correct but the window positions are awkward, you do not need to close and reopen anything.
category:
buffers-windows
tags:
#windows
#buffers
#command-line
#navigation
How do I append more commands to a recorded macro without re-recording it?
When a recorded macro is almost right but missing one repeated step, re-recording from scratch is usually slower and riskier than patching the register directly
category:
macros
tags:
#macros
#registers
#command-line
#normal-mode
How do I run a substitution across the arglist and write only modified files?
:argdo %s/foo/bar/ge | update
Bulk replacements across many files are risky when every buffer gets written unconditionally.
category:
command-line
tags:
#command-line
#arglist
#refactor
#ex-commands
How do I append a semicolon to every non-blank line with one Vim command?
:g/[^[:space:]]/normal! A;\<CR>
When you need to patch many lines at once, :g with :normal! is often faster and safer than recording a macro.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
How do I rerun a previous search pattern from history directly on the / prompt?
/\V<C-r>=histget('/', -2)<CR>
If you often alternate between two complex search patterns, opening q/ each time is slow.
category:
search
tags:
#search
#command-line
#history
#regex
#productivity
How do I apply a macro only to files that appear in the current location list?
:lfdo normal! @q | update
When you already have a curated location list, :lfdo lets you apply a change only to those files instead of touching your whole project.
category:
macros
tags:
#macros
#location-list
#refactoring
#command-line
#normal-mode
How can I print only arglist files that still contain trailing whitespace before bulk cleanup?
:argdo if search('\s\+$', 'nw') | echo expand('%') | endif
Before running destructive cleanup across many files, it helps to know which files will actually change.
category:
command-line
tags:
#command-line
#search
#whitespace
#arglist
#refactoring
How do I copy a register to another register while preserving its character/line/block type?
:call setreg('q', getreg('a'), getregtype('a'))
Simple register copies can silently change behavior when register type is lost.
category:
registers
tags:
#registers
#macros
#command-line
#editing
How do I run an Ex command on exactly the current visual selection without typing the range manually?
In Visual mode, typing : does more than open the command line: Vim automatically inserts the exact selection range as '.
category:
visual-mode
tags:
#visual-mode
#command-line
#ex-commands
#range