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.

So I have the following set in my vim:

set wrap linebreak textwidth=78

which wraps the line when you type more than 78 characters, HOWEVER! if you try and make a change in the middle of the line, this feature does not see to work anymore, the line does not softwrap properly, thus more than 78 character are placed in the line....

So I was wondering.. what do you do?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You are confusing the concepts of wrapping and formatting, as those concepts are used by Vim. Wrapping refers to the display of lines whose length exceeds the screen width. Formatting refers to the breaking and joining of lines by the insertion and deletion of newlines, usually so that all the lines are 'textwidth' or less in length.

The 'wrap' and 'linebreak' options affect how long lines are displayed. They do not affect the content of the lines. They affect how lines are wrapped at the right edge of the screen; their behavior is not affected by 'textwidth'.

The 'textwidth' option affects the point at which a line is broken by the addition of a newline as text is added to the line. This behavior is also affected by the 'wrapmargin' and 'formatoptions' options. The details of this behavior are discussed here:

:help 'formatoptions'
:help fo-table
:help 25.1

Vim has an auto-formatting capability that you might find useful. See

:help auto-format

It's too intrusive for my taste. I prefer to keep all my text within a textwidth of 78 for code and 68 for e-mail. Vim automatically adds a newline and puts the cursor on the next line when I append to a line and the length exceeds 'textwidth'. As I edit in the middle of lines the formatting becomes ugly, but I just wait until I have finished with that paragraph or comment, then reformat the whole thing with some variation of the gq command.

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.