Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim wrong syntax highlighting in Groovy

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.

like image 807
tlegutko Avatar asked Oct 22 '14 23:10

tlegutko


People also ask

Does vim support syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

How do I enable syntax highlighting in Vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Does vim have syntax highlighting for Python?

Vim comes with syntax highlighting for many popular languages, including Python, though it is not always the best one. There are several options to improve the default highlighting.


1 Answers

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

like image 50
tlegutko Avatar answered Sep 27 '22 22:09

tlegutko