How do I set the maximum line width for automatic text wrapping?
Answer
:set textwidth=80
Explanation
The textwidth option sets the maximum width for text. When you type beyond this width, Vim automatically inserts a line break.
How it works
:set textwidth=80wraps at 80 characters:set textwidth=0disables automatic wrapping- Only affects text as you type — existing lines are not reformatted
Example
With textwidth=80, typing beyond column 80 automatically starts a new line at the nearest word boundary.
Tips
gqreformats existing text totextwidth:set colorcolumn=80shows a visual guide lineformatoptionscontrols when wrapping is applied:set fo+=tenables auto-wrapping for text:set fo-=tdisables auto-wrapping (keeps manualgq)