Skip to content


Code folding in vim

I’ve been pushing off learning code folding in vim for a few weeks now. I ended that procrastination and I present to you a short tutorial on code folding in vim.


Code folding in vim from Bryan Liles on Vimeo.

The import things to remember here are to get your settings correct:

"folding settings
set foldmethod=indent   "fold based on indent
set foldnestmax=10      "deepest fold is 10 levels
set nofoldenable        "dont fold by default
set foldlevel=1         "this is just what i use

Then you can toggle folding with za. You can fold everything with zM and unfold everything with zR. zm and zr can be used to get those folds just right. Always remember the almighty help file at “help :folding” if you get stuck.

Happy hacking

Posted in Geek Vids, Smarticus Says.


8 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. nap says

    stop showing off… you and your scala code :)

  2. Evan Light says

    I was working on some hairy code in VIM, was thinking “I could really go for some code folding here”, and remembered seeing your article in Google Reader. Saved me some yak shaving. Thanks!

  3. mitjai says

    It's amusing how pretty much any VIm related post is certain to end with “help :whatever”. Not criticising but rather admiring the built-in help system.

  4. Praise Bob says

    Thanks for the folding info ;)

  5. Amit says

    Great one. Thanks.

  6. Aleksey V. Zapparov AKA ixti says

    Thanks for your tip!

  7. skrat says

    Thanks for the video, very helpful! Your wish has been granted, it helped me.

  8. n0dl says

    Thanks this helped out a lot, I no longer have to scroll through a mountain of text to get the peice of code I want



Some HTML is OK

or, reply to this post via trackback.

blog comments powered by Disqus


Blog WebMastered by All in One Webmaster.