Syntax highlighting in vim for python

PythonVimSyntaxViVim Syntax-Highlighting

Python Problem Overview


How do I do I set the syntax highlighting in Vim 7 for python?

I would like to set my own colorschemes, and syntax highlighting for a type of code file.

Python Solutions


Solution 1 - Python

The command to enable syntax highlighting in vim is :syntax on, if you want it to be active everytime you launch vim, just add a line containing syntax on in your .vimrc file.

Solution 2 - Python

Put the line syntax on in your .vimrc.

Solution 3 - Python

  1. Verify that you have the latest version of vim, equally execute sudo apt-get install vim
  2. Modify the .vimrc file with the instruction echo "syntax on" >> ~/.vimrc
  3. Open the file with vi app.py. You will see the Syntax highlighting

enter image description here

Solution 4 - Python

If you're on *nix system (linux, macos) or cygwin and if you already have vim :set syntax set but your filename doesn't end with .py you can add a shebang to the first line of your file:

#!/usr/bin/env python 

Next time you open the file in vim, you should see syntax highlighting. Note this will work for other file types, you just use the interpreter name i.e. (python, ruby, sh)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhidrotoView Question on Stackoverflow
Solution 1 - PythonmdeousView Answer on Stackoverflow
Solution 2 - PythonRobie BasakView Answer on Stackoverflow
Solution 3 - PythonRevol89View Answer on Stackoverflow
Solution 4 - PythonlacostenycoderView Answer on Stackoverflow