4

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?

2 Answers 2

5

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
1
  • :set formatoptions+=aw works PERFECTLY. Probably already saved me a couple of minutes of work just this evening!
    – Zut
    Feb 21, 2013 at 23:17
2

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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .