EDIT: I have fixed the problem I wanted to use 'foldmethod=syntax'
Behold my function to toggle code folding:
From my .vimrc:
Code:
nmap <silent> <F10> :call FoldComments() <CR>
let s:fold_comments = 0
function! FoldComments()
set foldmethod=syntax
if (s:fold_comments == 0)
let s:fold_comments = 1
set foldlevel=0
echo "Folding comments"
else
let s:fold_comments = 0
set foldlevel=9
echo "Unfolding comments"
endif
set foldmethod=manual
endfunction