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
/\vfoo\zsbar\ze/
Vim's \zs (start of match) and \ze (end of match) atoms let you control which portion of a pattern is treated as the actual match.
:%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.
:filter /pattern/ command
The :filter command restricts the output of another Ex command to only lines matching a given pattern.
o (in Visual mode)
When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored.
/pattern\zs.*\ze/
Vim's \zs (start of match) and \ze (end of match) atoms let you define a search pattern but only highlight or operate on a portion of it.
K
Pressing K in normal mode runs a lookup program on the word under the cursor.
navigation #navigation #help #documentation #normal-mode #keywordprg
"1p then u then . to cycle
Vim stores your last 9 deletions in numbered registers "1 through "9.
:ptag function_name
The :ptag command opens a tag definition in a small preview window at the top of the screen, letting you read the definition without losing your place in the cu
buffers-windows #buffers #windows #tags #preview #navigation
:autocmd WinResized * wincmd =
When you resize your terminal window, Vim's split layout can become unbalanced.
:set winfixheight
When you have a specific window you want to keep at a fixed size — like a terminal, log viewer, or reference file — winfixheight and winfixwidth prevent Vim
:lua vim.api.nvim_open_win(0, true, {relative='editor', width=80, height=20, row=5, col=10})
Neovim's floating windows hover above the main layout, creating popup-like UI elements.
<C-w>z or :pclose
The preview window shows file contents temporarily without switching your editing context.
buffers-windows #buffers-windows #quickfix #preview #navigation
<C-w>R
Vim provides commands to rotate windows within a row or column, and to swap the current window with another.
v3aw
In visual mode, repeating text object motions progressively expands the selection.
>gv
Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect.
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
:windo set wrap
Vim provides iterator commands that execute an Ex command across all windows, buffers, tabs, or argument list files.
buffers-windows #buffers-windows #windo #bufdo #batch-commands