1

Vim only seems to highlight comments, numbers, and imported modules. So function calls, attributes, etc are all non-highlighted. I have 'syntax on' and 'filetype plugin indent on' in my vimrc. syntax highlighting works with every other language EXCEPT python. I cant figure out why it doesnt like python. Any suggestions would be greatly appreciated!

I am using vim on mac terminal (vim Version: 8.1) installed via homebrew. I have verified that this is the version I am using.

EDIT: output of FT: Filetype=Python
Upon further research, it seems like perhaps my syntax highlighting is working, just not quit as good as I would of hoped. I thought I would be able to get similar syntax highlighting to something like atom

migrated from superuser.com May 12 at 17:16

This question came from our site for computer enthusiasts and power users.

  • 4
    What's the output of the command :set ft?. Also a screenshot might be good to get an idea. – Ralf May 12 at 18:38
  • 1
    This sounds like how it's supposed to look, as the Python syntax file doesn't highlight function calls. – Martin Tournoij May 14 at 1:13
0

I have extended the standard Python syntax file to cover your mentioned use cases:

  • Function calls
  • Attributes

As well as

  • variables (as distinct from object instances)
  • doctests
  • self
  • string formatting
  • et cetera

You can find it here, and use it as a drop-in replacement for the installed .../syntax/python.vim. You may also wish to extend the colour file you use to take advantage of the new syntax elements, as I have done here (but you may not like the actual colours there, many of my colleagues think them very garish).

However: do notice that it is based on the syntax file from Vim 6.1, so is missing some more modern aspects of the language (e.g. fstrings). (Contributions are very welcome.)

It also uses some features from Kien's Rainbow Parentheses, but they can be easily removed if you don't wish to use that.

Also in that directory is a syntax file to cover doctest files, i.e. doctests which are written to a separate test file, not merely added to docstrings within the main source file.

  • Thank you so much, your color scheme looks great! I've replaced my syntax file with yours, but it doesnt seem to have picked up on the extended syntax. I'll have to fiddle around some. Do you know if I'll have to change my vim version? – be_elle95 May 16 at 2:34
  • Don't think a Vim version change is needed. It has worked for me all the way since version 5 (I'm now on version 8) – jalanb May 16 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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