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

How do I open all nested folds under the cursor at once in Vim?

Answer

zO

Explanation

zO (uppercase O) opens the fold under the cursor and all folds nested inside it recursively. This exposes the full content of a deeply nested fold structure in a single keystroke, without needing to open each level individually.

How it works

  • zO — open the fold under cursor and all of its sub-folds, recursively
  • Compare with zo (lowercase): opens only one fold level at a time
  • The complementary command zC (uppercase C) closes the fold under cursor and all sub-folds recursively

Example

Given this file with two levels of folds, all closed:

+-- class Config (8 lines)--

After pressing zO with the cursor on that fold:

class Config:
    def __init__(self):      ← previously a nested fold, now open
        self.data = {}
    def validate(self):      ← previously a nested fold, now open
        return True
    def serialize(self):     ← previously a nested fold, now open
        return self.data

Tips

  • zo / zO — open one level / all levels recursively
  • zc / zC — close one level / all levels recursively
  • za / zA — toggle one level / all levels recursively
  • zR — open every fold in the entire file (all folds, not just under cursor)
  • zM — close every fold in the entire file
  • Use zO when diving into unfamiliar code that is heavily folded to quickly reveal everything in scope

Next

How do I mark and delete multiple files at once from within Vim's built-in file explorer netrw?