How do I create a fold from a visual selection?
Answer
zf (in visual mode)
Explanation
In visual mode, pressing zf creates a manual fold from the selected lines. This lets you collapse sections of code or text.
How it works
- Select lines with
Vand motions - Press
zfto create a fold - The selected lines are collapsed into one line
zoopens the fold,zccloses it
Example
Select a function body with Vip, press zf to fold it. The fold shows something like:
+-- 15 lines: function process() {----
Tips
:set foldmethod=manualmust be set for this to workzddeletes a fold (unfolds it permanently)zf{motion}creates a fold without visual modezRopens all folds,zMcloses all foldszatoggles the fold under the cursor