Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM folds for Everything except Something

Tags:

vim

folding

A code is over 2 000 lines full of folds. I select a certain block in Visual mode to which I would like to start writing. However, things around, such as folds, hinter 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 VIMs open. How can I hide everything except the block in folds?

like image 852
Léo Léopold Hertz 준영 Avatar asked Mar 23 '09 18:03

Léo Léopold Hertz 준영


2 Answers

You can do zMzv or zMzO.

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

like image 142
Paul Avatar answered Oct 27 '22 00:10

Paul


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.

like image 45
Arnis Lapsa Avatar answered Oct 26 '22 22:10

Arnis Lapsa