How do I reformat a paragraph to fit a specific line width in Vim?
gqap
The gq operator reformats text by wrapping lines to fit within the textwidth setting.
gqap
The gq operator reformats text by wrapping lines to fit within the textwidth setting.
:move +1 / :move -2
The :move command relocates lines to a specific position without using delete and paste.
:%norm A;
The :%norm command runs normal mode commands on every line in the file (or a range).
:%!tac
Vim doesn't have a built-in reverse command, but you can pipe the buffer through tac (reverse of cat) to flip line order.
:center 80
Vim has built-in text alignment commands that adjust lines relative to a specified width.
cia (with targets.vim) or daa
While Vim doesn't have a built-in argument text object, the targets.
<C-k>DG
Vim's digraph system lets you insert special characters by pressing followed by a two-character mnemonic code.
<C-r>=2+2<CR>
The expression register (=) in insert mode lets you evaluate any Vimscript expression and insert the result inline.
g<C-a> in visual mode
When you have multiple lines with the same number and want to turn them into a sequence (1, 2, 3.
:%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.