How do I collapse multiple consecutive spaces into a single space throughout a file?
:%s/\s\+/ /g
The pattern \s\+ matches one or more whitespace characters (spaces, tabs).
:%s/\s\+/ /g
The pattern \s\+ matches one or more whitespace characters (spaces, tabs).
guu / gUU
Vim's case operators gu (lowercase) and gU (uppercase) follow the same doubling convention as dd and yy: repeating the operator letter applies it to the whole c
<C-g>u
By default, Vim treats an entire Insert mode session (from entering Insert mode to pressing ) as a single undo unit.
:t.
The :t (short for :copy) command copies lines from one location to another.
r<CR>
You can split a line at the cursor without entering Insert mode by using r.
<C-t> / <C-d>
While in Insert mode, you can adjust indentation without switching back to Normal mode.
:center
The :center command pads a line with leading spaces so the text is centered within a given width.
<C-v>u{code} in insert mode
In insert mode, u followed by a 4-digit hex code inserts the Unicode character at that code point.
]p
The ]p command pastes text and adjusts its indentation to match the current line.
ciw + new text + Esc, then n.
The ciw command followed by new text, combined with and .
ci`
The ` ci ` command changes the text inside backtick delimiters.
V select then :norm A text
Selecting lines and running :norm A text appends the same text to the end of every selected line.
y$
The y$ command yanks (copies) text from the cursor position to the end of the line.
:earlier 10m
The :earlier command restores the buffer to its state at a specific time in the past.
:sort
The :sort command sorts lines in the current buffer or a specified range alphabetically.
ddp
The ddp sequence swaps the current line with the line below it.
:%s/\s\+$//
The :%s/\s\+$// command removes trailing whitespace (spaces and tabs) from every line in the file.
:m {line-number}
The :m (move) command moves the current line to after the specified line number.
<C-a>
The command increments the number under or after the cursor by 1.
X
The X command deletes the character to the left of the cursor (before it).