In this function I would like to substitute everything within ("
and ")
with emptiness
function! ListJoinFolds() abort
0
let bufnr = bufnr('%')
let items = []
while 1
let start = search('^{{{', 'cW')
if !start
break
endif
let end = search('^}}}', 'W')
let lines = getline(start, end)
let lines = map(lines, 'trim(v:val)')
call add(items, {
\ 'bufnr': bufnr,
\ 'lnum': start,
\ 'text': join(lines, ' '),
\ })
" credits to: https://www.reddit.com/r/vim/comments/akv0wl/function_sort_output_alphabetically/ef8nlrr
call sort(items, {a, b -> a["text"] == b["text"] ? 0 : a["text"] > b["text"] ? 1 : -1})
endwhile
call setloclist(winnr(), items)
lopen
endfunction
I've added the following nearly every thinkable order I could think of, but my intelligence couldn't find the right place to succeed for the attempted success.
let lines = substitute(items, '(".\{-}")', '', 'g')
Hopefully someone could assist me with this.
Thank you.
PS
I've also posted this question to:
reddit.com/r/vim (link)
If question solved, I will post it here, and vice versa.
f(g(), h(y()))
.. And unfortunately, regexes are really bad with recursive patterns.searchpair()
could have helped, but it works on buffers, not on strings. May be there is a Python library somewhere that can help, in that case it may be better to delegate your problem to that library from your vim function.