Question

A long time ago there was an editor called MultiEdit. It has a feature which I can not find in all powerful VIM. In MultiEdit I could press some hot key and it would show something like table-of-contents (aka, condensed-mode, aka outline) were I could see only 1st line of all functions (let it be C source) in current file. I could then move cursor to function that I need and after pressing enter, mode will switch to normal and I would be in function that I need. Very useful for those who likes to put many functions in one file. This feature was extremely simple to use: one config option to enter regex for selecting title-lines and one hotkey for mode toggle.

VIM has folding. But this is different. Folding hides parts of files and displays folded-lines-indicator. It is much more difficult to specify what to hide in folds for table-of-content-display: you need to start fold at title-line and end before next title line. This is more complex than simple regex to select titles.

I so much wanted this feature, I even wrote VIM macro to emulate this MultiEdit behavior, even though I don't know VIM that much. I've wrote it in part because it was easier to to learn a new language and write a macro than to figure out VIM folding module complexity. Unfortunately, after upgrading VIM, this macro now does not work (infinite loop?). I've wrote it long time ago, and what little I did know about VIM is all forgotten and I could not fix it now. (EDIT: I've fixed my script. Thanks to @romainl for the link).

My question is how to get this table-of-content like display in VIM?

Was it helpful?

Solution

This recent vimcast by Drew Neil explains the generalities of folding and this one goes through the process of creating the kind of folding you are (probably) after.

Depending on the language you work with and your coding style, something as simple as

set foldmethod=marker
set foldmarker={,}

and zM can get you a long way:

CSS folding

If you want to customize what information is displayed, the second link above is almost certainly just what you need.

OTHER TIPS

Have a look at ctags and the vim plugin tagbar.

You also check out the vim plugin unite with the extension Unite-Ouline it gives a behavior quite close to what you describe.

It's not great but have you tried setlocal foldmethod=syntax? It seems to do a decent job in 7.3 on Windows. ...although I just realized that our coding standard has the opening brace for a block at the end of the line rather than on a new line and if I change to having it on a new line it works substantially less well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top