简体   繁体   中英

How do I report the first line of each fold in Vim?

I thought that

:folddoc execute v:foldstart."p"

would work, but it only repeatedly returns the first line of just one of the folds.

Thanks.

The first line of a closed fold can be detected using the foldclosed() function. For a given line number inside of a closed fold, it returns the number of the line that fold starts on; otherwise, it returns -1. Obviously, if a line's number equals to the value of foldclosed() for that number, then the line is the first one in a fold. In Vimscript this test can be written as

foldclosed('.') == line('.')

Therefore, to print the first lines of all closed folds, one can use the following command:

:folddoc if foldclosed('.') == line('.') | # | endif

(Use the :p command instead of the :# one when displaying line numbers is not necessary.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM