Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim code folding - remap shortcut to toggle code folding

Tags:

vim

vi

folding

Is there way to map e.g. F9 in .vimrc to toggle fold all/unfold all folds?

like image 603
Anthony Avatar asked Oct 17 '25 10:10

Anthony


1 Answers

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

like image 144
selyunin Avatar answered Oct 19 '25 00:10

selyunin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!