Easily open and close folds
From Vim Tips Wiki
[edit] Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
Tip 1330 Previous Next Created: September 17, 2006 Complexity: basic Author: Peter Hodge Version: 5.7
If you're finding that 'zo' and 'zc' are hard to type or remember, you could use <spacebar> and <backspace> to open and close folds:
nnoremap <Space> zo nnoremap <backspace> zc
Or, you could just use the <spacebar> to do both:
nnoremap <Space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
[edit] Comments
Using za is easier - see :help za.
Better add the following mappings:
inoremap <F9> <C-O>za nnoremap <F9> za onoremap <F9> <C-C>za vnoremap <F9> zf
With these mappings, one can create folds in Visual mode and open/close folds in the other modes.
Space already works out of the box for opening folds. The idea for backspace to close again is a good one and will surely make it into my .vimrc :)
zA - toggle open/close folds recursively.
Tip 108 is better than this. It won't affect normal functionality of <Space> when cursor is not on folding.
