120

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.

4 Answers 4

171

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.

If you're already editing a Python file and syntax highlighting wasn't on, after enabling syntax highlighting (as above) then: :set filetype=python

Sign up to request clarification or add additional context in comments.

9 Comments

maybe your vim doesn't have filetype detection enabled, try adding filetype on to your .vimrc or type :set filetype=python while editing a file.
i think that vim is broken becuse :help gives E433: No tags file E149: Sorry, no help for vi_help.txt Press ENTER or type command to continue
maybe try reinstalling it, either with your package manager or from sources, never had these errors, can't help you for this.
thanks anyway it may have something to do with useing "..The vim-minimal package includes a minimal version of VIM,...." according to package manager
@hidroto vim-tiny by default provides no help, or any of the truly powerful features of vim.
|
15

Put the line syntax on in your .vimrc.

Comments

9
  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

1 Comment

this is the answer for my case, tx
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.