How to highlight commas not followed by a space in vim

vimvimrc

I've gotten into the habit of not appending spaces after commas in lists, when coding.

To break this habit, I thought I'd get vim to highlight any comma (,) that is not followed by a space.

So I've added this to my .vimrc:

highlight SquishedCommas ctermbg=red guibg=red
match SquishedCommas /,(?! )/

However, it doesn't seem to highlight anything!

Best Answer

The syntax for lookarounds in vim is different from the PCRE syntax that you appear to have assumed. Instead of (?! ) try \@! i.e.

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