I have some text that is folded, and I would like to operate on the entire fold (e.g. with y
), agnostic of what kind of fold it is and how it is defined.
Is there some general function to obtain the start and end of the current fold under the cursor?
For example, suppose I am editing an XML file with g:xml_syntax_folding = 1
set:
<outerElem>
<innerElem id=1>
<thing>Hello</thing>
</innerElem>
<innerElem id=2>
<thing>here is</thing>
</innerElem>
<innerElem id=3>
<thing>some stuff.</thing>
</innerElem>
</outerElem>
The standard syntax folding will create one fold for the outerElem
and one fold for each of the innerElem
s. This is what my editor would look like (with an ␣
representing the cursor) if I open the outerElem
fold, but leave the innerElem
folds closed:
<outerElem>
+--- 3 lines: <innerElem id=1>
+--- 3 lines: <innerElem id=2>
␣--- 3 lines: <innerElem id=3>
</outerElem>
I would like an operator (or functions I can use to write an operator) that corresponds to "the entire innerElem
fold", so that I can delete/yank it, reindent it, etc. using all the usual Vim commands that accept operators.
I am aware of [z
and ]z
, but this requires the fold to be open already, which I do not want to have to do.
I use Neovim, so I am also open to a Neovim-only solution.
I do not want a solution that only works on XML, or on any specific kind of fold. I am only looking for a general solution that can operate on any fold, defined using any valid fold method.
Update: For now, I am going to just work with the z[
, z]
, zj
, and zk
commands. I will also take a look at the auto-origami source code to see if it's possible to make a "current fold" text object :)
zj
andzk
get to what you want?