vimtricks.wiki Concise Vim tricks, one at a time.

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

  • foldcolumn controls the dedicated fold-sign column at the left edge
  • auto tells Vim to size that column dynamically based on current fold display needs
  • :3 sets 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=99 if you prefer opening files with folds expanded.
  • If you also use signs (LSP/git), tune signcolumn separately to avoid gutter jitter.
  • In very narrow splits, reducing the cap to auto:2 can preserve more text width.

Next

How do I preview a fuzzy tag match in the preview window without immediately switching buffers?