I'd like to map a key to toggle between foldmethod=indent
and no folding. How can I do that?
I'd say zi (toggle foldenable) does the job.
No mapping required. (see also :he folding
)
(You could also look at zM and zR)
Since you want to map it to a single key, proceed as follows:
:nnoremap <F10> zi
To force the foldmode to indent
each time (not really recommended for me), you'd need a function:
Add the function to your vimrc[2]:
function ForceFoldmethodIndent()
if &foldenable
se foldmethod=indent
endif
endfunction
nnoremap <F10> :normal zi^M|call ForceFoldmethodIndent()^M
inoremap <F10> ^O:normal zi^M|call ForceFoldmethodIndent()^M
Let me know if that works for you. I appreciate if you accept this answer if it does :)
Cheers
[1] with behave mswin
[2] To enter the special keys (e.g. ^O
) in commandline or insertmode use e.g.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With