How do I run a normal mode command on every line matching a pattern?
:g/pattern/normal {cmd}
Combining :global with :normal lets you run any normal-mode keystrokes on every line that matches a pattern.
:g/pattern/normal {cmd}
Combining :global with :normal lets you run any normal-mode keystrokes on every line that matches a pattern.
<C-v>u{hex}
In insert mode, pressing followed by u and a 4-digit hexadecimal codepoint inserts the corresponding Unicode character directly into the buffer.
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
<C-y> and <C-e>
In Insert mode, copies the character at the same column position from the line above the cursor, and copies the character from the line below.
:%s/pattern/\U&/g
Vim's substitute replacement string supports special case-transform atoms that change the case of matched text without requiring a second pass or an external to
<C-a> (insert mode)
While in insert mode, pressing re-inserts the exact text you typed during your previous insert session.
:earlier
Vim's undo history is not just a linear list of changes — it records timestamps too.
!{motion}{command}
The ! operator filters the text covered by a motion through an external shell command, replacing the original lines with the command's stdout.
[p
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.
<C-x>s
When spell checking is enabled (:set spell), s in insert mode opens a popup menu of suggested corrections for the most recently flagged misspelled word — with
:sort u
The :sort u command sorts all lines in the buffer (or a selected range) alphabetically and removes duplicate lines in a single pass.
{count}<C-a> / {count}<C-x>
While increments and decrements a number by 1, you can prefix either with a count to add or subtract a specific amount.
:'<,'>!sort -t',' -k2 -n
Vim does not have a built-in multi-column sort, but you can leverage the external sort command to sort selected lines by any field.
editing #editing #sorting #ex-commands #external-commands #command-line
:set complete+=kspell
Vim's built-in completion ( / ) sources matches from buffers, included files, and tags by default.
<C-k>
Vim has a built-in digraph system that lets you type special characters using short two-character codes.
:m +1
The :move command (abbreviated :m) relocates lines to a new position in the buffer without touching any registers.
!{motion}{program}
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
=i{
When editing code with messy indentation — after a paste, a merge conflict, or a refactor — you often need to fix just one block rather than the entire file
:g/pattern/m 0
The :global command combined with :move lets you restructure a file by relocating all lines that match a pattern.
<C-v>{char}
When you need to insert a literal tab character despite expandtab being set, or embed a control character like ^M (carriage return) into your text, in insert mo
editing #editing #insert-mode #special-characters #control-characters