temporarily disabling foldclose=all

366 views Asked by At

My current vim configuration is set to auto close folds once the cursor moves out from their area with:

set foldmethod=syntax
set foldclose=all

That works really well. Therefore, I often feel the need of focus on 2 different fold section at the same time (i.e: two if statements in different positions).

Unfortunately, the above becomes impossible with foldclose set to all considering the fact that by moving the cursor out of the first if clause it will make the previous to close immediately.

By any chance, is there any way to temporarily mark that fold so it won't be influenced by foldclose=all while I check both clauses and one finished, I can simply remove that blocking flag so it will come back to normal?

I think that the syntax method is the one that serves me well since it is usually what I look for when working with language specific folding.

2

There are 2 answers

0
Prince Goulash On BEST ANSWER

As far as I know, this is not possible.

However, you could cheat by splitting the window (:split). This allows the cursor to be in a different position in each window, so you can have a different fold open in each.

0
Alvaro9366 On

You just need to set the foldclose option temporarily to nothing and then set it to all again.

So, anywhere in the document you type:

:set foldclose=<CR>

(Nothing after the =)

Then you can open the folds you want to work with, and when you're done just set the option back with:

:set foldclose=all<CR>

Extra:

If you're folding manually then I recommend using the option:

set foldcolumn=1   " Or 2, 3, ...

to have a visual aid of where the folds begin and end, and also their depth level at the left margin of the document, next to the line number column.

Image of my current _vimrc file