1

In my syntax file I have something like

syn match cleanReal "[+-~]\?\<\d\+\.\d+\(E[+-~]\?\d+\)\?" display
hi def link cleanReal Float

Is there a way to get all strings that are matched as cleanReal from vimscript?

I'm asking because I would like to write a custom command completion function that completes all strings matched by some syntax group.

1

The last time I've tried something similar, it was to emulate ]s long before it existed. I proceeded by going from word to word until I find one with the right synId*() value.

You could do that, but I'm afraid that it'll be very slow.

If your syntax group it just a regex that you know, and with no context or whatever (like exclusion within comments or strings), may be the easier approach would be to get all matches from getline(1,'$')

let text = join(getline(1,'$'), "\n")
let matches = []
call substitute(text, yourregex, '\=add(res, submatch(0))', 'g')
let matches = uniq(sort(matches))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy