Posts | About

Vim Formatting Essentials

vimcheet-sheetsvideo

Posted on 2024-09-01 by Matt.

Cheat Sheet

Formatting Lines

gq docs or :h gq

Format the current line

gqq

Format selected text. Mnemonic: GQ Magazine is fashionable and this operation makes your text fashionable.

gq

Configure maximum width used by gq and enable auto line-breaks at 120 cols (local to buffer)

" vimscript config
set textwidth=120
-- lua
vim.bo.textwidth = 120

Disable textwidth

" vimscript config
set textwidth=0
-- lua
vim.bo.textwidth = 0

Shifting

<< docs or :h <<

Shift lines one shiftwidth left.

<<

Shift lines one shiftwidth right.

>>

Use . operator to shift multiple levels of indentation.

>>..
<<..

Shift a paragraph one shiftwidth left or right.

>ap
<ap

Indentation

= docs or :h =

Auto-indent selected lines

=

Auto-indent a paragraph

=ap