vimtricks.wiki Concise Vim tricks, one at a time.

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=80 wraps at 80 characters
  • :set textwidth=0 disables 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

  • gq reformats existing text to textwidth
  • :set colorcolumn=80 shows a visual guide line
  • formatoptions controls when wrapping is applied
  • :set fo+=t enables auto-wrapping for text
  • :set fo-=t disables auto-wrapping (keeps manual gq)

Next

How do you yank a single word into a named register?