Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When editing files that I limit in my .vimrc to tw=80, when I come back to edit them later, the line-lengths end up all over the place. e.g.

lets say for the sake of argument that this line hits 80 characters
there and continues on the next line as normal

After editing...

lets say for the sake of argument (edit edit edit edit) that this 
line hits 80 characters
there and continues on the next line as normal

Instead of

lets say for the sake of argument (edit edit edit edit) that this 
line hits 80 characters there and continues on the next line as 
normal

Anyone know what I can do to fix this behaviour?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use the "gq" normal-mode command to reformat text. It works on a visual selection, or with a motion. For example, you can use the text-object "ap" (which can be used in place of a motion) which means "a paragraph" (the current paragraph that the cursor is on):

gqap

Or you could visually select the paragraph(s) you want to reformat and just type "gq".

Another trick is to add "a" and optionally "w" to the 'formatoptions' option:

:set formatoptions+=aw

This will automatically reformat paragraphs as you type, without needing to resort to "gq".

See:

:help gq
:help auto-format
:help 'formatoptions'
:help motion.txt
share|improve this answer
    
:set formatoptions+=aw works PERFECTLY. Probably already saved me a couple of minutes of work just this evening! –  Zut Feb 21 '13 at 23:17

What you are looking for is vi formatoptions. To turn on text wrapping:

:set fo+= t

Sources:

ftp://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf

http://blog.ezyang.com/2010/03/vim-textwidth/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.