Syntax highlighting in vim for python

111,387

Solution 1

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

Put the line syntax on in your .vimrc.

Solution 3

  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

Share:
111,387
hidroto
Author by

hidroto

Updated on March 10, 2020

Comments

  • hidroto
    hidroto about 4 years

    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.

  • mdeous
    mdeous over 13 years
    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.
  • hidroto
    hidroto over 13 years
    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
  • mdeous
    mdeous over 13 years
    maybe try reinstalling it, either with your package manager or from sources, never had these errors, can't help you for this.
  • hidroto
    hidroto about 13 years
    thanks anyway it may have something to do with useing "..The vim-minimal package includes a minimal version of VIM,...." according to package manager
  • SDsolar
    SDsolar almost 7 years
    Pretty hard to detect a filetype unless it reads the first line of the file. I never use extensions for commands. filetype=python seems to work.
  • D. Ben Knoble
    D. Ben Knoble over 5 years
    @hidroto vim-tiny by default provides no help, or any of the truly powerful features of vim.
  • Amy Pellegrini
    Amy Pellegrini almost 5 years
    None of this works for me. Tried adding filetype on and syntax on on .vimrc, also :set filetype=python while editing the file, and added the shebang as suggested elsewhere :(
  • John
    John over 4 years
    @hidroto, a tag file must be created independently of Vim. One easy option is to use a program like Exuberant Ctags, which will do it for a whole directory tree in one quick command. See the Vim docs (which are good) at vimdoc.sourceforge.net/htmldoc/usr_29.html#29.1, and vimways.org/2018/you-should-be-using-tags-in-vim.
  • Alex M.M.
    Alex M.M. over 3 years
    this is the answer for my case, tx
  • enator
    enator over 3 years
    for noobs not knowing the location of .vimrc file, here you go: echo "syntax on" >> ~/.vimrc