Is there a way to get fold data? I'm trying to figure out how folds effect the line numbers of the buffer. I've found some work arounds that do a lot to get this information (saving state, unfolding everything, check if foldables sections line by line, then returning to prev state), but it seems like there should just be a function that I can call similar to winsaveview that will say something like "lines 3-5 are folded". Does this exist? (searching help and google hasn't turned up anything.)
I guess the simplest way is to iterate over lines and find which are folded
function! Folds() abort
let folds = []
let i = 1
while i <= line('$')
let foldends = foldclosedend(i)
if foldends != -1
call insert(folds, [i, foldends])
let i = foldends
endif
let i = i+1
endwhile
return folds
endfunction
:echo json_encode(Folds())
@nbardiuk Thanks, I think this is just what I was looking for!
for ref https://www.vim.org/scripts/script.php?script_id=732