Vim Tips Wiki
(Oops. Version 7.2. Right.)
(restore comments, template entries, and some deleted content. This tip content is good since Vim 5.something, I think.)
Line 3: Line 3:
 
|previous=988
 
|previous=988
 
|next=990
 
|next=990
|created=June 15, 2010
+
|created=September 9, 2005
 
|complexity=basic
 
|complexity=basic
|author=Matt Phipps
+
|author=
|version=7.2
+
|version=6.0
 
|rating=127/50
 
|rating=127/50
 
|category1=Usage
 
|category1=Usage
Line 15: Line 15:
 
<pre>
 
<pre>
 
:set wrap
 
:set wrap
:set lbr
+
:set linebreak
 
</pre>
 
</pre>
   
<tt>wrap</tt> tells Vim to word wrap visually (as opposed to changing the text in the buffer), and <tt>lbr</tt> tells Vim to only wrap at a character in the <tt>breakat</tt> option (by default, this includes "<tt> ^I!@*-+;:,./?</tt>" (note the inclusion of " " and that <tt>^I</tt> is the control character for Tab)).
+
This will get Vim to wrap existing text as desired. <tt>wrap</tt> tells Vim to word wrap visually (as opposed to changing the text in the buffer), and <tt>linebreak</tt> tells Vim to only wrap at a character in the <tt>breakat</tt> option (by default, this includes "<tt> ^I!@*-+;:,./?</tt>" (note the inclusion of " " and that <tt>^I</tt> is the control character for Tab)).
  +
To make settings permanent, without the need to type this every time you use Vim, just add the commands to your vimrc (without the colon).
 
  +
In addition, you will need to prevent Vim from automatically inserting line breaks in newly entered text. The easiest way to do this is:
  +
  +
<pre>
  +
:set textwidth=0
  +
:set wrapmargin=0
  +
</pre>
  +
  +
If you want to keep your existing 'textwidth' settings for most lines in your file, but not have Vim automatically reformat when typing on existing lines, you can do this with:
  +
  +
<pre>
  +
:set formatoptions+=l
  +
</pre>
  +
 
To make settings permanent, without the need to type this every time you use Vim, just add the commands to your [[vimrc]] (without the colon).
  +
  +
==References==
  +
*{{help|'wrap'}}
  +
*{{help|'linebreak'}}
  +
*{{help|ins-textwidth}}
  +
  +
==See also==
  +
*{{help|'showbreak'}} if you want to see text to show the difference between "soft" and "hard" wrapped lines.
  +
  +
==Comments==
  +
I'm not certain whether 'wrapmargin' is always turned off when it is set equal to zero, but it seems to work. Is this always the case?
  +
  +
--[[User:Fritzophrenic|Fritzophrenic]] 17:47, June 15, 2010 (UTC)

Revision as of 17:47, 15 June 2010

Tip 989 Printable Monobook Previous Next

created September 9, 2005 · complexity basic · version 6.0


When editing a text file, if you want word wrapping, but only want line breaks inserted when you explicitly press the Enter key:

:set wrap
:set linebreak

This will get Vim to wrap existing text as desired. wrap tells Vim to word wrap visually (as opposed to changing the text in the buffer), and linebreak tells Vim to only wrap at a character in the breakat option (by default, this includes " ^I!@*-+;:,./?" (note the inclusion of " " and that ^I is the control character for Tab)).

In addition, you will need to prevent Vim from automatically inserting line breaks in newly entered text. The easiest way to do this is:

:set textwidth=0
:set wrapmargin=0

If you want to keep your existing 'textwidth' settings for most lines in your file, but not have Vim automatically reformat when typing on existing lines, you can do this with:

:set formatoptions+=l

To make settings permanent, without the need to type this every time you use Vim, just add the commands to your vimrc (without the colon).

References

See also

  • :help 'showbreak' if you want to see text to show the difference between "soft" and "hard" wrapped lines.

Comments

I'm not certain whether 'wrapmargin' is always turned off when it is set equal to zero, but it seems to work. Is this always the case?

--Fritzophrenic 17:47, June 15, 2010 (UTC)