How do I make the fold column appear only when needed and cap its width?
Answer
:set foldcolumn=auto:3
Explanation
If you use folds heavily, a fixed fold column is a tradeoff: foldcolumn=0 hides useful fold cues, while a constant width wastes horizontal space in files that barely fold. :set foldcolumn=auto:3 gives you a dynamic gutter that grows only when fold markers are needed, up to a maximum width of three columns. It keeps the editing area clean while still exposing fold structure when it matters.
How it works
foldcolumncontrols the dedicated fold-sign column at the left edgeautotells Vim to size that column dynamically based on current fold display needs:3sets an upper bound so deep nesting does not consume too much screen width- With this setup, shallow files often show no fold gutter, while deeply nested regions get just enough visual scaffolding
Example
Without dynamic sizing (fixed width):
|+| function outer() {
|+| if (cond) {
|+| while (...) {
...
With foldcolumn=auto:3:
| | function outer() {
|+| if (cond) {
|+| while (...) {
...
The fold gutter appears only where it contributes signal.
Tips
- Pair this with
set foldlevelstart=99if you prefer opening files with folds expanded. - If you also use signs (LSP/git), tune
signcolumnseparately to avoid gutter jitter. - In very narrow splits, reducing the cap to
auto:2can preserve more text width.