Python3 has the matrix multiplication operator (@
) which is used to multiply numpy
matrices. But when we write something like A = B @ C
in vim, the @ C
portion gets highlighted. Apparently Python has these things called decorators which also use @
. Vim's syntax highlighting seems to confuse the operator for the decorator. We basically want the following:
A = B@C # <-- Operator, this should look just like B+C
A = B \
@C # <-- Still operator, '\' makes it multi-line
@D # <-- Decorator, should be highlighted
The culprit seems to be this line from the python.vim
file (I used the latest version from here):
syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
It doesn't check if the @
is being used as an operator.
So I have two questions.
- How to get vim to highlight correctly?
- How to do this without mucking around with
/usr/share/vim/vim74/syntax/python.vim
(or whatever system file is being used)?
I don't think I will be using decorators, so one option is to just comment out the offending line above. But this requires us to manipulate system files.
syntax clear pythonDecorator
to.vim/after/syntax/python.vim
to remove the syntax item.~/.vim/syntax/python.vim
to override the default one, which should probably work (unless it uses newer Vim features, I didn't check/test).