Folding in vim

T

Terry Hancock

My general attitude towards IDEs and editors has been
extremely conservative, but today I decided to see what
this "folding" business was all about.

I see that vim (and gvim, which is what I actually use)
has this feature, and it is fairly nice, but at present it's
very manual --- and frankly it's hard for me to see the
point if I have to manually mark folds every time I start
up.

I tried to load a couple of different scripts to
automatically fold Python code in vim, but none of them
seems to do a good job.

The obvious thing (to me) would be for functions and
classes to be folded at the top level, with each method
folded inside the class folds. But I can't seem to figure
out how to make that happen (other than manually,
I mean). Actually, I usually want to fold the comment
block at the top with the license disclaimer and module
documentation, too, but I can do that manually.

I've tried:
python_fold.vim by Jorrit Wiersma
http://www.vim.org/scripts/script.php?script_id=515
and
AutoFold.vim by Dave Vehrs
http://www.vim.org/scripts/script.php?script_id=925

Does anybody have a better suggestion (or perhaps can
tell me how to make one of these do what I'm wanting)?

I'm assuming that I can set these by using the
Tools -> Folding -> Fold Method -> Syntax
(or Expression for python_fold)

but it doesn't seem to work. python_fold seems to just
collapse methods (but not the whole classes they are in),
and I can't seem to make AutoFold do anything at all, so
I must be using it wrong.
 
R

Ron Adam

Terry said:
My general attitude towards IDEs and editors has been
extremely conservative, but today I decided to see what
this "folding" business was all about.

I see that vim (and gvim, which is what I actually use)
has this feature, and it is fairly nice, but at present it's
very manual --- and frankly it's hard for me to see the
point if I have to manually mark folds every time I start
up.

I been trying to learn and use the 'Cream' distribution of Vim.

http://cream.sourceforge.net/

Playing around with it a bit....

If I highlight any block of code... then press F9 it folds it. Put the
cursor on the fold and pressing F9 again unfolds it. It remembers the
folds, so putting the cursor anywhere in the previous folded area and
pressing F9 again refolds the fold. Folds can be inside of folds.

Saving the file exiting and reopening it... the folded folds remained
folded. I'm not sure where it keeps the fold info for the file.

The folds don't have anything to do with classes or functions, but are
arbitrary selected lines, with the first line displayed after the number
of lines folded. So a whole file gets reduced to...

1 # SliderDialog.py
2
3 +--- 20 lines: """ SIMPLE SLIDER DIALOG -------------------------
23
24 +-- 24 lines: # Imports------------------------------------------
48
49 +-- 13 lines: # Values extracted from win32.com------------------
62
63 +-- 67 lines: class SliderDialog(dialog.Dialog):-----------------
130
131 +-- 4 lines: def GetSliderInput( title, text, label, value=0 ):-
135
136 +-- 17 lines: if __name__ == '__main__':-------------------------
153

Pretty cool, I'll probably use folding more now that I've played with it
a bit.

I like Vim-Cream, but I still haven't gotten the script right for
executing the current file in the shell. And a second script for
executing the current file in the shell and capturing the output in a
pane. I think some of it may be windows path conflicts.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top