How do I count substitution matches before changing anything?
:%s/pattern/replacement/gn
When you are about to run a broad substitution, it is often safer to measure impact first.
command-line #command-line #ex-commands #substitution #search
2125 results for "i' a'"
:%s/pattern/replacement/gn
When you are about to run a broad substitution, it is often safer to measure impact first.
command-line #command-line #ex-commands #substitution #search
"1p
Vim automatically stores your deletion history in numbered registers "1 through "9.
"*
On X11 Linux systems, there are two independent clipboard-like buffers: the primary selection (") and the clipboard ("+).
g- and g+
Vim's undo history is a tree, not a linear stack.
:set winminheight=0
By default, Vim enforces a minimum window height of 1 line, which means you can never fully collapse a split.
buffers-windows #buffers-windows #windows #splits #navigation
:set conceallevel=2
The conceallevel option controls how Vim displays characters that have the "conceal" syntax attribute.
* (in visual mode)
In normal mode, searches for the word under the cursor with word-boundary anchors.
:set updatetime=250
The updatetime option controls how long Vim waits after you stop typing before triggering certain events (like swap file writes and CursorHold autocommands).
:Gitsigns preview_hunk
gitsigns.
:ALEFix
ALE (Asynchronous Lint Engine) is a popular Vim plugin that runs linters and formatters asynchronously in the background, showing errors and warnings in the gut
:2match Todo /FIXME/
Vim provides three independent match slots — :match, :2match, and :3match — each of which highlights a pattern using a specified highlight group.
zt
The zt command repositions the viewport so that the line where your cursor sits moves to the top of the screen, without changing your cursor position within the
navigation #navigation #scrolling #normal-mode #viewport #productivity
ge
The ge motion moves the cursor backward to the end of the previous word.
:%retab!
The :retab command converts leading whitespace according to the current tabstop and expandtab settings, but it only touches indentation at the start of lines.
v, V, or Ctrl-V while in visual mode
How it works Vim has three visual modes, and you can switch between them without losing your current selection: v - Characterwise visual mode (select individual
:.t$
The Ex command :.
:ls +
The :ls command (or :buffers) supports filter flags that narrow the buffer list to specific states.
:%s/#\zs\d\+/\=printf('%04d', submatch(0))/g
For log files, changelogs, or issue references, you sometimes need fixed-width numeric IDs without touching surrounding syntax.
editing #editing #ex-commands #substitute #regex #text-processing
: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.
:arglocal
By default, Vim's argument list is global, so changing it in one window can unexpectedly affect another workflow in a different tab or split.