How do I delete a fold definition at the cursor without deleting the underlying text?
Answer
zd
Explanation
zd removes the fold definition at the cursor position — the text inside the fold is not deleted. This command is available when foldmethod is set to manual or marker. It is useful when you want to unfold a region permanently, or reorganize your fold structure without touching the buffer content.
How it works
zd— delete the fold directly under the cursorzD— delete the fold and all nested folds inside it (recursive)- Only works with
foldmethod=manualorfoldmethod=marker - For
markerfolds,zdremoves the{{{/}}}fold markers from the text - For
manualfolds,zdremoves the fold from Vim's internal fold list without modifying the buffer
Compare this to zo (open fold) and zc (close fold), which are temporary view changes. zd is a permanent structural change.
Example
With foldmethod=manual and a fold around lines 5–12:
+-- 8 lines: function foo() {-------------
With cursor on that fold line, pressing zd removes the fold:
function foo() {
...
}
The text is untouched; only the fold definition is gone.
Tips
- Use
zEto eliminate all folds in the window at once - After
zdon amarkerfold, the{{{and}}}comment markers are deleted from the file - Pair with
zf{motion}to create new folds andzdto remove them as your code structure evolves :set foldmethod=manualto switch to manual folding if you're currently using another method