Text Wrapping in Vi

A really quick way to wrap text to a defined number of columns in ‘vi’ is to use


The “%” selects the entire document, the “!” replaces the paragraph with output from the ‘fmt’ program. The ‘fmt’ program will, by default, wrap lines to 80 columns. If you’d like something different, you can simply type the number of columns like so

:%!fmt 50

Take a look at the ‘fmt’ man page for more options. Also, this :%! trick doesn’t just work with fmt, it works with programs like awk too. Have fun!

Apparently, “{!}fmt” will only wordwrap the paragraph which can be incredibly handy… I haven’t been able to reproduce the success from Mac OSX with VIM. Thoughts?

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 0 Comment So Far

Share your thoughts, leave a comment!