Is the line complicated? - How to check folds in VIM

I am writing some bending functions, and I am at the point where I need to check if the current line is really a bend.

The reason for this is because it is a custom fold method that depends on finding / matching specific strings.

For example, if the current line adds up and looks like this:

-FOO------------------------ 

If you do something like:

 getline('.') 

You basically get FOO , so I don’t know (I know that I know) if I am in focus or not.

Is there a helper function for this?

I would think that it should be something like:

 is_folded('.') 

Perhaps I could associate with foldtext to assign a special header for the fold, but I want to avoid this.

+6
function vim folding
source share
1 answer

From :help eval.txt

foldclosed ({lnum})

The result is Number. If the line {lnum} is in a closed fold, the result is the number of the first line in this fold. If the string {lnum} is not in a closed layer, -1 is returned.

You can check for a given line if it returns -1 or line number, you can probably implement your isfolded() function this way.

If you are looking for a Vim script function or function, it is a good idea to start by looking at eval.txt , which contains a lot of relevant information.

+6
source share

All Articles