How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?
\@=
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@ family of atoms.
\@=
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@ family of atoms.
[[
The [[ and ]] commands navigate between top-level code blocks — specifically, lines where { appears in column 1.
:'<,'>s/\%Vpattern/replacement/g
When you press : after making a visual selection, Vim inserts ' to restrict the substitution to the selected lines.
visual-mode #visual-mode #search #editing #ex-commands #normal-mode
/\cfoo
Vim's \c and \C flags let you force a search to be case-insensitive or case-sensitive on a per-search basis, regardless of your ignorecase and smartcase setting
:let @q='commands'
Macros in Vim are stored in registers as plain text.
:%s/\%Vpattern/replacement/g
The \%V atom restricts a regex match to the last visual selection — more precisely than :'s/.
"%p
Vim has several read-only registers that hold special values.
]'
The ]' command jumps to the start of the line containing the next lowercase mark in the file, while [' jumps to the previous one.
:match {group} /{pattern}/
:match lets you apply a highlight group to any pattern in the current window without touching the buffer or its syntax rules.
:set nrformats+=alpha
By default, and only increment and decrement numbers (decimal, hex, and octal depending on format).
:s/pattern/\=expression/g
Prefixing the replacement string with \= in a :substitute command tells Vim to evaluate the rest as a VimScript expression rather than literal text.
:let @a = @a . @b
You can manipulate register contents directly using the :let command with the @{reg} syntax.
:'<,'>norm @a
Combining :normal with a visual range lets you replay a macro on each line of a selection individually — far more targeted than recursive macros or @@ repeati
:let @a = "value"
The :let @{reg} = expr command lets you assign any string or expression directly into a named register without entering insert mode or performing a yank.
:s/,/,\r/g
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
' vs `
Vim provides two distinct ways to jump to a mark, and they behave differently: the apostrophe ' jumps to the first non-blank character of the marked line, while
\C
Vim's \C and \c atoms let you override ignorecase and smartcase on a per-pattern basis.
@q
A recursive macro is a macro that calls itself as its last step, causing it to loop automatically until an operation fails (such as reaching the end of the file
:let @/ = 'pattern'
Writing to the @/ register via :let @/ = 'pattern' sets Vim's last-search pattern directly — without performing a search or moving the cursor.
:set opfunc and g@
Vim's operatorfunc option lets you define your own operators — just like the built-in d, y, or c — that accept any motion or text object.