Is there way to map e.g. F9 in .vimrc to toggle fold all/unfold all folds?
1 Answer
In your .vimrc file:
Use the following command to set your desired keystroke (change <C-F5>
which is Ctrl+F5 to the combination you like):
noremap <C-F5> :call UnrolMe()<CR>
The function UnrolMe()
toggles all unrolling (i.e. it subsequently calls zR
and zM
commands)
let $unrol=0
function UnrolMe()
if $unrol==0
:exe "normal zR"
let $unrol=1
else
:exe "normal zM"
let $unrol=0
endif
endfunction
Change zR and zM to the unrolling commands of your choice (see https://www.linux.com/learn/tutorials/442438-vim-tips-folding-fun for the list of commands). Hope this helps
nnoremap [anything] zM
to fold everything andnnoremap [anything] zR
to open all folds.