How do I collapse consecutive duplicate words across a file?
:%s/\v<(\w+)\s+\1>/\1/g\<CR>
OCR cleanup, copy-paste artifacts, and rushed note-taking often produce repeated words like the the or is is.
640 results for "/pattern"
:%s/\v<(\w+)\s+\1>/\1/g\<CR>
OCR cleanup, copy-paste artifacts, and rushed note-taking often produce repeated words like the the or is is.
:{range}command
Every Ex command in Vim can be preceded by a range that specifies which lines it should operate on.
command-line #command-line #ex-commands #ranges #editing #productivity
mzgUiw`z
When you run an operator like gUiw, Vim can leave your cursor in a slightly different place than where you started.
*Ndgn
When you are reviewing repetitive text, you often need to remove one specific match without running a broad substitute.
:%s/\v^([^,]+),([^,]+),/\2,\1,/<CR>
When CSV-like data has two columns in the wrong order, manually fixing each line is slow and error-prone.
: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.
:sort
The :sort command sorts lines in the current buffer or a specified range alphabetically.
:[range]sort /regex/
The :[range]sort /regex/ command sorts lines while skipping the portion of each line that matches the regex.
/\%>10l\%<20lpattern
Vim's \%>Nl and \%10l matches only after line 10 \%10l\%10l\%<20lold/new/g Combine with column restrictions for precise region targeting Tips Line numbers in \%
/foo\|bar
How it works The \ operator in Vim's search pattern works like a logical OR, letting you match any one of several alternatives.
:%s/,/,\r/g
In Vim substitutions, \n and \r behave differently depending on whether they appear in the search pattern or the replacement string — a common gotcha that sur
:let @/ = '\V' . escape(@0, '\')
When the text you yank contains regex characters, a normal / search can produce noisy or surprising matches.
:s/\n/ /
One of the most confusing asymmetries in Vim's substitution syntax: \n and \r mean different things depending on whether they appear in the pattern or the repla
:doautocmd
:doautocmd fires any autocommand event manually, exactly as if that event had occurred naturally.
:keeppatterns normal! @q<CR>
When you replay macros from Ex commands, Vim can overwrite @/ (the last search pattern) depending on what the macro does.
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
cgn
The cgn command combines the change operator with the gn motion to change the next occurrence of your last search pattern.
:let @b = @a
The :let @b = @a command copies the contents of register a into register b.
:help topic
Vim has an extensive built-in help system.
searchcount()
The searchcount() function returns a dictionary containing the current search state: which match the cursor is on, how many total matches exist, and whether the