Code folding in VIM 6.0+
Here’s a neat little feature I’ve just been introduced to. After coding in VIM for so many years, one might think I’d know these things, but as it turns out, there’s a lot of features in VIM I’m not using. This one, however, will likely be a time-saver. There are a number of different code folding methods available in VIM (:help folding). I use the marker method by including this in my .vimrc file:
set foldmethod=marker
I can then use the following commands from command mode (not colon mode):
- At the beginning of a function fragment, you can type ‘zfap’ to create a fold; this should add some {{{ }}} tags around your code in the comment of choice for the language you’re coding in.
- You can type ‘zo’ to open a fold, or I can just hit the right arrow key on the folded code marker.
- You can type ‘zc’ to close a fold.
- You can type ‘zr’ to open all folds.
- You can type ‘zm’ to close all folds.
More commands are available in :help folding.









2 Comments