2

Following up on this question on how to highlight commas not followed by a space; the accepted answer provides a nice solution for problems like:

func(a, b,c,d)

But it also highlights commas at the end of a line (after longname2):

func(longname1, longname2,
     longname3)

There I would actually like to highlight the opposite case, i.e. if there actually was a space behind longname2, (which is already handled by the highlighting of trailing spaces).

Is there a way to extend/modify this command:

highlight SquishedCommas ctermbg=red guibg=red
match SquishedCommas /, \@!/

To only highlight the SquishedCommas if they are not at the end of a line?

1 Answer 1

1

match SquishedCommas /, \@!/

You are actively highlighting commas, that are not followed by a space. But in fact you want to only highlight commas that are not at the end of line and are not followed by a space. I think this change to your :match command will achieve this:

match SquishedCommas /,\%($\| \)\@!/

That will highlight commas, that are not at the end of the line and not followed by a space.

Note: the :match function is a window local function. That means it won't work after splitting a new window.

1
  • I always get crazy by things like /,\%($\| \)\@!/ and have to study exactly how it works, but I just tested it and this is exactly what I was looking for. Thanks!
    – Bart
    Commented Jun 9, 2018 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.