8
3
In vim, I typically set foldmethod
to indent
for most file types. In general, I like files to open with all folds open. However, it is useful to start immediately using zm to start closing folds globally across the file, one level at a time, allowing me to see the overall structure of the file without details getting in the way.
The only general solution I have found is to set foldlevelstart
to a very high number, e.g. 99, to make sure that all files (bearing in mind different files will have different levels of maximum indent) start completely unfolded. However, I'd then have to use zm repeatedly to reduce foldlevel
down to the maximum fold level of the file, normally much less than 99, which is cumbersome and impractical. I could set foldlevel
manually using the vim command line, but I'd still need to know the maximum indent in the file.
Is there a practical way to open a file with foldlevel
set to exactly one more than the maximum current indent/fold level in the file itself?
For example, given the following file:
a
b
c
d1
d2
e
f1
f2
The first keypress of zm would show this:
a
b
c
+-- 2 lines: d1------
e
+-- 2 lines: f1------
(Note, however, that it should work for the general case where the initial maximum indent of the file could be any value).
1You're confusing
zr
withzm
; the latter reduces the foldlevel. – Ingo Karkat – 12 years ago@IngoKarkat, you're right, I am. Sorry for the confusion - I always find those key combos counter-intuitive. I've fixed my question. – Andrew Ferrier – 12 years ago
"I always find those key combos counter-intuitive." It's supposed to mean
zm
= fold more (subtract foldlevel) andzr
= fold less (add foldlevel) – wisbucky – 11 years ago