5
votes

when I do the single slash (/) when typing some arithmetic expression (like val1 / val2), my vim treats it as a comment for multiple lines (/*). The result looks like:

enter image description here

I now I can escape it by typing ;/ at the end of that line (which closes the comment), but it is still annoying and I'd like for my vim to behave properly :).

I've tried using another vim syntax highlighting package for groovy, I've tried :filetype plugin off in my .vimrc, I've tried purging vim with my settings and reinstalling it and the problem is still there.

1
I just checked in vim 7.3.762 and that's all ok. May be some plugin breaks highlighting. - xio4
You want :filetype plugin indent on in your vimrc. Does this happen with vim -u NONE? - FDinoff
and i can confirm with 7.4.273 - so it might be an regeression and you should report it. - cfrick
at a very first glance it looks like it could be 4339:22fa3049e934 with changes to groovyELExpr, so vim now thinks the / starts a regexp. - cfrick
@cfrick you're right :). that was the solution. don't know how to vote you up though :( FDinoff, vim -u NONE did prevent the bug, but it also prevented any syntax highlighting :). - tlegutko

1 Answers

12
votes

SOLUTION:

As pointed out by @cfrick, vim (my version: 7.4) treats '/' as beginning of regular expression in groovy. The solution is to edit

/usr/share/vim/vim74/syntax/groovy.vim

And around line 260-261 there is

syn region groovyString           start='/[^/]'  end='/' contains=groovySpecialChar,groovyRegexChar,groovyELExpr

Just change the start to

start='/[^*/]'

Edit: changed space in regexp to * as @calid suggested in comment below

start='/[^ /]'

(that is add the space there.)

And now it looks much better. On the other hand it will now not highlight regexps starting with space, but for me it's okay. At least it's much better than what it was.

This helped mi a lot with finding my solution: Groovy syntax highlighting in Vim 7.4