Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I asked on /r/vim about "Who uses folds?" Didn't get any takers. I always forget they exist and haven't used them in my workflow yet.

Tag files would be another good one.



I use them all the time (I've switched them on by default in .vimrc) while editing C++ code. Extremely, extremely helpful to get the structure of a file at a glance. For example, if a 400-line file has about 10 functions in it, you can fold all "zM" and instantly you see only the function signatures, while the bodies are folded.

How to enable it: use "set foldmethod=syntax" (with C++) or "set foldmethod=indent" (with JS, where "syntax" doesn't work for me). Also, I use "set foldminlines=0" so that 1-line paragraphs get closed as well (it looks more consistent).

How to use it: close all folds "zM" (I remember it because the M is shaped like it's all folded on itself). Open all folds "zR". Open one fold "zo", close one fold "zc". Open one fold recursively "zO", close one fold recursively "zC".

By the way, I almost never use manual folds, so "zf" is almost useless to me.


I use folds for one specific thing: I have a general "notes" file for home and for work, which is a big outline where I put anything I'm thinking about or working on. I usually don't delete stuff, so the file grows over time. I make a fold for each top-level item (~project or subproject) and sometimes nested folds if things get too big. I always use fdm=marker. The automatic fold methods are too confusing.

Everyone uses tag files, in some sense, when they use :help :)


I don't use folds that often, but when I do they are be extremely helpful. When you run across that block of code that's way longer than it should be, and need to collapse it so you can see the context around it, folds can be very useful. Also for taking care of long comment blocks.

So while I agree with you in that they aren't a part of my typical workflow, they are a piece of vim that I'm glad I familiarized myself with.


I couldn't live without folds. Whether I'm in C++, Java, Go, Ruby, or a custom ASCII report I've written, I use them extensively. I add fold tags around every method/function implementation, and sometimes an additional one around around groups of them (e.g., classes). I generally set foldlevel to 0, so most files I enter have a few intro lines and then N folds, so that even large (1000+ lines) source files fit into a single page or two. I almost never use searches or tags to find declarations, since I can usually navigate to them directly with a single keystroke.

FWIW, I map <Space> to za, so that I can unfold/refold quickly. I also map - to zx to quickly fold up a file I may have drilled some holes in.


I use them for learning a library or framework. I'll fold all of the functions, methods, etc. in a file and and then unfold to dig deeper. I work on a 13" mba so it helps with the lack of vertical screenspace.


I still don't fully understand how folds work (e.g., how can I get them in my JavaScript files by default?), and thus I find them difficult to work with, but when I can get them to work, I'm very glad of them. They make navigating round a large file much easier.


I use them. They don't help as much with new development, but when editing a large pre-existing code base it makes perusing the contents of a file much easier. It's like getting a table of contents for free if your code is cleanly organized.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: