Tip: #1091 - Hide/show parts of your code
Created: December 29, 2005 16:29 Complexity: basic Author: http://sabji.blogspot.com Version: 6.0 Karma: 79/34 Imported from: Tip#1091
Sometimes you see too much code,
To organise the code clutter in your screen
You can hide/show blocks of code (not) of interest to you
(this tip does not change your source file, only the display)
1. Put this in your vimrc:
:set foldmethod=manual
:map + v%zf
2. Now put your cursor on any parenthesis of block you want to hide (fold) and press '+' key.
3. You can also view/unfold the hidden block by just pressing space inside the folded text.
4. To find out more about this feature do,
:help folding
5. To hide arbitary block, use these key strokes:
v<move>zf
Comments
One more tip for C coders, put this in .vimrc and use Alt-a to open/close blocks of {code}:
- syn region myFold start="{" end="}" transparent fold
- syn sync fromstart
- set foldmethod=syntax
- map <A-a> za
googler , December 30, 2005 21:55
And for comments:
- syn region Comment start="/\*" end="\*/" fold
Anonymous , December 30, 2005 21:59
If you program in Java and you hide all your useless code .. What are you going to see ?
- -)
Happy New Year everyone !!!
Jerry
macosx--AT--rocteur.cc , December 31, 2005 7:17
hey googler,
very very useful tip, thanks!!
vineeth , January 2, 2006 21:52
hi googler,
i put your code under _vimrc (windows) , but it doesnt work :(
everytime i start vim , i have to redo the first line (:syn region myFold start="{" end="}" transparent fold ) to get the folding. any suggestions?
john , January 3, 2006 2:49
For your vimrc (here I am using F4 to toggle folds):
function! Mosh_C_fold()
" :syn region Comment start="/\*" end="\*/" fold :syn region myFold start="{" end="}" transparent fold :syn sync fromstart :set foldmethod=syntax
endfunction
- map <F4> za
au FileType c,cpp,java :call Mosh_C_fold()
http://sabji.blogpspot.com , January 3, 2006 11:49
When I use this function, for some reason it folds away from the opening { all the way to the end of the file, rather than ending the fold at the matching }. This forced me to consider foldmarker instead.
salmanhalim--AT--hotmail.com , February 23, 2006 13:13
Thanks you very much. It's very useful for me.
sakharin--AT--gmail.com , January 26, 2007 0:47