9

A code is over 2000 lines full of folds. I select a certain block in Visual mode to which I would like to start writing. However, things around the block, such as folds, hinder my writing, and I accidentally tend to modify them. Currently, I avoid such mistakes by writing the block in a separate vim. It is not a real solution, and it gets awkward with too many vim's open.

How can I hide everything except the block in folds?

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

2 Answers2

17

You can do zMzv or zMzO.

zM closes all folds
zv makes the current line visible
zO opens all folds under cursor recursively up to root

(O in zO is the uppercase "oh" character, not zero 0)

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Paul
  • 13,042
  • 3
  • 41
  • 59
6

Not exactly what you asked for, but might work...

Map this friend to something:

:vnoremap <Leader>za <Esc>`<kzfgg`>jzfG`<

I have it on leader => z (because it has to do w/ folding) => a (because it stands for "around")

Usage:

Select lines with V, hit leader z a.
Everything above and below will be folded.

Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195
  • 1
    Wow. That's perfect. Just want to mention that `:nmap zs zRzz` is a nice way to unfold everything back – vrybas Dec 15 '12 at 07:11