What Folding Is
Folding in vim works by condensing lines of text/code into a single line. This is extremely useful for large coding projects where you would like to be able to quickly scan through your code and only unfold portions when you need to view them. Since pretty much all good programers use indentation when programming we will set vim to fold based on indentation level.
Before we get started on how to use folding in vim, I will show you a couple before and after pics of some sample code with and without folding.
Before - No folding
After - With Folds
Ok now that you understand what folding is lets discuss how to to do it in vim.
How To Fold in 3 Easy Steps
- type ":set foldmethod=indent"
- move your cursor to the first line of code you would like to fold and type "za". This should cause all the lines at that same level (and sub levels) and be condensed into a single line.
- If you want to expand the text/code you just folded then move your cursor to the line folded line and type "za" again.
Key Bindings To Know
- za - toggles a fold
- zc - closes a fold
- zo - opens a fold
- zR - open all folds
- zM - closes all folds
More Info
This is just a very basic overview of one way to do folding in vim. There are many other ways to do folding besides based on indentation. To learn more about folding I recommend checking out
http://vim.wikia.com/wiki/Folding
--
Posted By Conrad Sykes to
The Computer Kid at 6/22/2013 12:27:00 AM