1

There are a few commands to use folding (amongst all):

za      When on a closed fold: open it. [...]
        When on an open fold: close it [...]

zA      When on a closed fold: open it recursively.
        When on an open fold: close it recursively [...]

However my "ideal" keystroke (which would be most commonly used), would be:

        When on a closed fold: open it recursively.
        When on an open fold: close it (only one, like in `za` command)

How to define such a mapping?

1
nnoremap <expr> <leader>z foldclosed('.') != -1 ? 'zO' : 'zc'

See :h :map-<expr>. On a fold, use zO to open it recursively, otherwise use zc to close one fold.

0

You don't need to create a mapping, just use the zc/zC and zo/zO commands.

zc will close the fold at the current line, and zC will close all of the folds at the current line, while zo and zO will open one level and all levels of folds at the current line, respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.