Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any command to toggle enable auto text wrapping?

Tags:

vim

By default, I think my vimrc setttings enable the auto-wrapping. However, sometimes, I would like to see text lines are not wrapped. Is there any command I toggle the text line wrapping enabled and disabled? This would avoid me to exit and to change settings.

like image 391
David.Chu.ca Avatar asked Sep 02 '25 14:09

David.Chu.ca


2 Answers

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 :_!
like image 161
Jeremy Cantrell Avatar answered Sep 05 '25 14:09

Jeremy Cantrell


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.

like image 27
m0j0 Avatar answered Sep 05 '25 16:09

m0j0