Wikia

Vim Tips Wiki

Changes: Toggle auto-wrap

Edit

Back to page

(Adjust previous/next navigation)
(Remove html character entities)
Line 16: Line 16:
 
#Wrap long line at will (good for email and text).
 
#Wrap long line at will (good for email and text).
   
Following is the map I figured out, using <C-B> in this example:
+
Following is the map I figured out, using <C-B> in this example:
   
 
<pre>
 
<pre>
 
set sr fo=roqm1 tw=64
 
set sr fo=roqm1 tw=64
im &lt;C-B&gt; &lt;C-O&gt;:setl sr! fo&lt;C-R&gt;=strpart("-+",&amp;sr,1)&lt;CR&gt;=tc&lt;CR&gt;_&lt;BS&gt;&lt;Right&gt;
+
im <C-B> <C-O>:setl sr! fo<C-R>=strpart("-+",&sr,1)<CR>=tc<CR>_<BS><Right>
 
</pre>
 
</pre>
   
By default, it goes without auto-wrap. If I want, I can type &lt;C-B&gt; to toggle auto-wrap. Another &lt;C-B&gt; toggles back.
+
By default, it goes without auto-wrap. If I want, I can type <C-B> to toggle auto-wrap. Another <C-B> toggles back.
   
 
Basically it toggles two settings:
 
Basically it toggles two settings:
   
 
<pre>
 
<pre>
:set fo+=tc&lt;CR&gt;
+
:set fo+=tc<CR>
:set fo-=tc&lt;CR&gt;
+
:set fo-=tc<CR>
 
</pre>
 
</pre>
   
strpart() is used for toggling; "sr" is choosing for no good reason; "_" can be any char; &lt;BS&gt;&lt;Right&gt; is needed to toggle this action.
+
strpart() is used for toggling; "sr" is choosing for no good reason; "_" can be any char; <BS><Right> is needed to toggle this action.
   
 
==Comments==
 
==Comments==
 
I found on Unix, we don't need the last part of the map.
 
I found on Unix, we don't need the last part of the map.
   
im &lt;C-B&gt; &lt;C-O&gt;:setl sr! fo&lt;C-R&gt;=strpart("-+",&amp;sr,1)&lt;CR&gt;=tc&lt;CR&gt;
+
im <C-B> <C-O>:setl sr! fo<C-R>=strpart("-+",&sr,1)<CR>=tc<CR>
   
 
----
 
----

Revision as of 08:43, September 29, 2008

Tip 441 Printable Monobook Previous Next

created March 11, 2003 · complexity basic · author Xiangjiang Ma · version 6.0


In insert mode, I would like to

  1. Keep typing without auto-wrap (good for editing vimrc and c).
  2. Wrap long line at will (good for email and text).

Following is the map I figured out, using <C-B> in this example:

set sr fo=roqm1 tw=64
im <C-B> <C-O>:setl sr! fo<C-R>=strpart("-+",&sr,1)<CR>=tc<CR>_<BS><Right>

By default, it goes without auto-wrap. If I want, I can type <C-B> to toggle auto-wrap. Another <C-B> toggles back.

Basically it toggles two settings:

:set fo+=tc<CR>
:set fo-=tc<CR>

strpart() is used for toggling; "sr" is choosing for no good reason; "_" can be any char; <BS><Right> is needed to toggle this action.

Comments

I found on Unix, we don't need the last part of the map.

im <C-B> <C-O>:setl sr! fo<C-R>=strpart("-+",&sr,1)<CR>=tc<CR>

Just found that it is not related Unix or Windows.

It is a settting of virtualedit. For current vim version (6.1), if we

:set virtualedit=insert

We need the last part in the map, otherwise, we don't need it.


Around Wikia's network

Random Wiki