History
Article Edit this page Discussion

Toggle auto-wrap

From Vim Tips Wiki

(Redirected from VimTip441)
Jump to: navigation, search

Tip 441 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.

[edit] 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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Toggle auto-wrap"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation