Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:34:39+00:00 2026-06-09T12:34:39+00:00

I am trying to highlight a member variable in Vim using c.vim plugin. For

  • 0

I am trying to highlight a member variable in Vim using c.vim plugin.

For example, in

struct sockaddr_in sa;
sa.sin_family = AF_INET;

I want to highlight sin_family.

So, here is my syntax match code:

syn match   cCustomMember "\(\.\)\@<=[a-zA-Z0-9_]\+\s*\((\)\@!"
hi def link cCustomMember Number

Basically what I am trying to say here is that there must be a . in front, followed by multiple words characters, optionally followed by whitespace, and make sure no bracket is following.

But the above syntax highlighting regular expression doesn’t seem to work correctly in Vim.
For example, if i have code like this:

getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());

.msg and .code are highlighted except the last letter is not. But I don’t want to highlight the member function (ends with a round bracket)

I think it’s kinda similar to this Regex problem in python:

a = re.compile("(?<=\.)(?:\w+)(?!\()")
print a.search(".test(").group() #produces tes, which it's desired to match nothing
print a.search(".test").group()  # produces test

how to negative lookahead for a whole group rather than individual letters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:34:41+00:00Added an answer on June 9, 2026 at 12:34 pm

    Explanation

    The issue you are struggling with is due to the fundamental way how modern regex engines operate when looking for matches, called backtracking. Jan Goyvaerts put it succinctly in his post “Unintended Backtracking Can Bite You”:

    Back­track­ing oc­curs when the reg­u­lar ex­pres­sion en­gine en­coun­ters a regex to­ken that does not match the next char­ac­ter in the string. The regex en­gine will then back up part of what it matched so far, to try dif­fer­ent al­ter­na­tives and/or rep­e­ti­tions. Un­der­stand­ing this pro­cess will make all the dif­fer­ence be­tween guess­ing and un­der­stand­ing why a reg­u­lar ex­pres­sion match­es what it does and doesn’t.

    In your case, the regex engine will backtrack when the lookahead assertion is matching, testing for shorter combinations which match – and both .cod and .ms do. The following shows what happens, with the vertical bar delimiting the characters already consumed by the regex from the rest of the string .code():

    .|code()   # good start => try next char
    .c|ode()   # matches => try next char
    .co|de()   # matches => try next char
    .cod|e()   # matches => try next char
    .code|()   # whoops, next char is "(" => track back
    .cod|e()   # matches => we’re done here
    

    Note this is only true when you use greedy quantifiers, as you do in your code; a lazy quantifier would match .c. See the Regex Tutorial on lazy versus greedy quantifiers.

    Solution

    The obvious way to step around this problem would be to prohibit backtracking before the lookahead, effectively “locking” the part of the pattern the regex has already consumed up to there: member functions would never match. Some regular expression engines will allow you to do exactly this using atomic grouping or even a possessive quantifier (which is essentially syntactic sugar for atomic grouping) – the better known are those listed on the pages linked before. Vim’s regex engine, however, is not one of them.

    A somewhat less straightforward and rather more brittle way is to redefine what you are looking for: instead of a negative lookahead assertion matching an opening paren, use a positive lookahead assertion matching all valid characters separating member variables from other code (whitespace, comma, semicolon, closing paren, end of line – check your source for more) – essentially anything but an opening paren and another name character. I’ll leave it to you translate this into Vim’s regex syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a Java library to highlight code. I don't want to
I am trying to highlight a link of a currently opened category tab, here
I'm trying to highlight a text in the html string by using Html Agility
I am trying to highlight a table row using Jquery's .hover() method. I have
I am trying to highlight a row in an NSTableView using a CALayer .
I'm trying to highlight the search results but I want to include the surrounding
I am trying to highlight the word that has been passed in using regex
I'm trying to highlight just one specific row in a table using jQuery. The
I'm trying to highlight every digit sequence in a text using the Highlight method.
In vim I am trying to have it highlight my screen when it goes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.