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.
:g/pattern/m $
The :g (global) command combined with :m (move) lets you collect all lines matching a pattern and relocate them to a specific position in the file.
command-line #ex-commands #editing #global #search #formatting
:%Subvert/old{,s}/new{,s}/g
Tim Pope's vim-abolish plugin provides the :Subvert command (aliased as :S), which performs substitutions that automatically preserve case variants and handle p
plugins #plugins #substitution #editing #ex-commands #search
:let @+ = @"
Vim's :let @{reg} syntax lets you read from one register and write to another.
o (in Visual mode)
When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored.
"1p then u then . to cycle
Vim stores your last 9 deletions in numbered registers "1 through "9.
>gv
Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect.
<C-v>j$A;<Esc>
When lines have varying lengths, a normal visual block selection stops at the shortest line.
<C-v>jjxp
Visual block mode lets you select, cut, and paste rectangular columns of text.
: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.
:cnoremap <C-a> <Home>
Vim's command line has limited navigation by default.
<C-w>_ and <C-w>|
When working with multiple splits, you sometimes need to focus on one window temporarily without closing the others.
:set suffixesadd+=.js,.ts,.py
In many programming languages, import statements reference modules without file extensions (e.
:set virtualedit=block
By default, Vim's visual block mode () is limited by line length — if some lines are shorter than others, the block selection gets ragged.