I'm writing some folding functions and I am at a point where I need to check if the current line is actually a fold.
The reason for this is because it is a custom fold method that depends on searching/matching certain lines.
For example, if the current line is folded and looks like:
-FOO------------------------
If you do something like:
getline('.')
You would basically get FOO
so there is no way (that I know of) to know if I am at a fold or not.
Is there a helper function for this?
I would think it would have to be something like:
is_folded('.')
I could probably mess with the foldtext
to assign a special title for the fold but I want to avoid this.
Vim folding commands zf#j creates a fold from the cursor down # lines. zf/string creates a fold from the cursor to string. zj moves the cursor to the next fold.
However, it works by adding special markers to your buffer text so that the same folds can be loaded by anyone opening the file in Vim. The markers are defined by the 'foldmarker' option, which defaults to three consecutive open curly braces to start a fold and three consecutive closed curly braces to end a fold.
Using Vim’s folding features, you can tuck away portions of a file’s text so that they’re out of sight until you want to work with them again. Here’s how. Vim’s folding commands begin with z — which, as the Vim docs point out, sort of looks like a folded piece of paper. OK, maybe not much, but at least the commands are consistent.
Unfortunately, Vim is a little less than tidy in this regard — if a search causes a fold to be expanded, Vim doesn’t re-fold the text after moving the cursor outside the fold. However, a quick zm will restore the folds.
From :help eval.txt
foldclosed({lnum})
The result is a Number. If the line {lnum} is in a closed fold, the result is the number of the first line in that fold. If the line {lnum} is not in a closed fold, -1 is returned.
You can check for a given line if it returns -1 or a line number, you can probably implement your isfolded()
function this way.
If you are looking for Vim script function or feature , it is a good idea to start by searching in eval.txt
which contains lots of relevant information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With