Picture of Michael Lee
:wave: Hey hey, I'm Michael Lee and this is my site about being a developer, being a dad and making side projects.
Sponsorship

Toggle word wrap in Vim

Written on November 15, 2018

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 in when I do need the copy in front of me to be word wrapped I could turn it off 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.

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design and side projects. Sign up and I'll send you my articles straight to your email.