When editing email, I have "hard wrap" enabled most of the time. However, I sometimes want to turn it off (or back on), which I do with the following commands in ~/.vimrc.

" turn off
command HardWrapOff :set formatoptions-=t
" turn on
command HardWrapOn :set formatoptions+=t

Is there a way to use a single command to toggle it depending on the current state?


There's no builtin way of doing this that I'm aware of, but you could use a conditional like so:

command HardWrapToggle if &fo =~ 't' | set fo-=t | else | set fo+=t | endif
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.