1

I never thought of the use of foldcolumns in vim. There are - and + signs to indicate foldable or folded parts of the code, that I understand. But what about the numbers inside the cosecutive - signs? If I increase foldcolumn width the numbers take another form. I learned that the numbers help to identify foldable parts properly. Can someone explain its use?

I read foldcolumn.txt, folding.txt and foldmethods.txt and I still don't understand foldcolumns!

2

They indicate folds and their nesting levels:

A + plus symbol marks a closed fold, and a - minus marks the first line of an open fold.

If foldcolumn is high enough (i.e. greater that the number of open nested folds currently being displayed), then each nested open fold will be preceded by a bar character |, so if you have 3 nested open folds you will see a display something like this:

     not in a fold
-    start of fold 1
|    inside fold 1
|-   start of fold 2
||   inside fold 2
||-  start of fold 3
|||  inside fold 3
|||+ closed fold 4
|||  inside fold 3
|||  end of fold 3
||   inside fold 2
||   end of fold 2
|    inside fold 1
|    end of fold 1
     not in a fold

However, if you decrease the size of foldcolumn so there is no longer enough room to use this style of display), then nested bar characters will be replaced with digits as necessary:

e.g., with the example above, if you execute :set foldcolumn=3, there is not enough room for three nested | characters and a + sign, so numbers are used instead as necessary:

     not in a fold
-    start of fold 1
|    inside fold 1
|-   start of fold 2
||   inside fold 2
2-  start of fold 3
23  inside fold 3
23+ closed fold 4
23  inside fold 3
23  end of fold 3
||   inside fold 2
||   end of fold 2
|    inside fold 1
|    end of fold 1
     not in a fold

With foldcolumn=1 the number of | characters that can be displayed is even more restricted:

  not in a fold
- start of fold 1
| inside fold 1
- start of fold 2
2 inside fold 2
- start of fold 3
3 inside fold 3
+ closed fold 4
3 inside fold 3
3 end of fold 3
2 inside fold 2
2 end of fold 2
| inside fold 1
| end of fold 1
  not in a fold

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.