Is there any command to toggle enable auto text wrapping?

In your vimrc, create a function such as this:

:function ToggleWrap()
: if (&wrap == 1)
:   set nowrap
: else
:   set wrap
: endif
:endfunction

Then map a key (such as F9) to call this function, like so:

map <F9> :call ToggleWrap()<CR>
map! <F9> ^[:call ToggleWrap()<CR>

Whenever you press F9, it should toggle your wrapping on and off.


I think what you want is:

:set wrap!

This will toggle line wrapping.

More about using ! (bang) to alter commands can be found at:

:help :_!

Tags:

Vim