For example, if I want to search for \<data\> but I want to skip any entries appearing in multi-line block comments like this:

 * Don't match comments containing the term 'data'

I can't just use zero-width negative-lookbehind \(\*.*\)\@<!\<data\> because the block comments don't always start with a * on each line.

It seems like it would be difficult/impossible to exclude matches inside multi-line block comments, but syntax highlighting is able to identify which sections are comments and which are not, so is there any way to tie in the regex search with syntax highlighting groups?

If it's possible to tie in to the syntax highlighting groups, I'd be able to not only exclude the terms appearing in comments, but also the terms that appear in strings, like this:

output = "Sample data: '"+data+"' ...";

And only the data in the middle there outside of the quotes would be matched.

Anyone know if this is possible?

EDIT: Searching excluding comments is definitely is possible at least. I could define a search() function and check the highlight group from inside that, as indicated by someone on in this thread. Relevant portion:

use search() and then check if the syntax highlight group is comment. If synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name") is Comment, call search() again.

But I don't think this would leave the hlsearch highlighting the right terms.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.