Wrap Existing Text at 80 Characters in Vim

Dan Croak

You have an existing block of text or code in vim. You want to re-format it to wrap to 80-characters.

:set textwidth=80

You might want this setting to apply automatically within certain file types like Markdown:

au BufRead,BufNewFile *.md setlocal textwidth=80

We have that setting in thoughtbot/dotfiles.

Select the lines of text you want to re-format:

v

Reformat it:

gq

Learn more:

:h gq

What’s next

If you found this useful, you might also enjoy:

We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.