Toggle word wrap in Vim

Written on November 15, 2018
Updated on June 20, 2023

By default, I’ve got Vim set up to not word wrap. While this is useful for writing code, it sometimes is a nuisance when writing notes or posts for my site as the sentences are cut off past the current view.

Toggling is pretty straightforward in Vim, so in instances when I do need the copy in front of me to be word wrapped I could turn it on and then quickly turn it off again.

Command to turn on word wrap in Vim

To turn on word wrap in Vim, you’ll want to enter this sequence of characters in normal (command) mode:

:set wrap

This will immediately word wrap all the sentences in the current document that is open in the buffer.

Command to turn off word wrap in Vim

To turn off word wrap in Vim in the current document that is open, you’ll want to enter this sequence of characters in normal (command) mode:

:set nowrap

Command to toggle word wrap in Vim

While :set wrap will turn on word wrap in Vim and :set nowrap will turn off word wrapping, you can also use both commands with the ! (bang) symbol to toggle word wrap.

So using either:

:set wrap!

or

:set nowrap!

Will both toggle word wrap in the current document in the buffer.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share articles like this one in your inbox. Sign up for my newsletter.