Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python syntax support for Vim on Mac OSX?

Tags:

python

vim

I recently started programming in python and have fallen in love with Vim over the past few weeks. I know want to use Vim as my primary editor for python files. I know there are python plugins for Vim, but I am very confused as to where/how I can install these. I don't really understand where Vim is installed. I'm running the latest version of Mac OS X Snow Leopard.

Any help would be greatly appreciated. Thanks!

like image 476
readmymsg123 Avatar asked Jan 10 '11 22:01

readmymsg123


People also ask

How do I enable syntax highlighting in vim Mac?

If you want to toggle this on/off (without creating a . vimrc file) simply type :syntax on while in vi/vim.

How do I enable Python syntax highlighting in vim?

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. maybe your vim doesn't have filetype detection enabled, try adding filetype on to your .

Where is Vimrc on Mac?

The path used by macOS's default vim install is /usr/share/vim/vimrc .

Does my vim support Python?

Vim already comes with syntax highlighting for a huge number of programming languages that includes Python. There are three plugins that help to improve it - one is called python-syntax, the other one is python-mode, and the third one is python. vim.


2 Answers

To best answer your initial question: "How to install python syntax support in Vim":

There is no need to install anything! If you have not made any modifications (e.g. no configuration changes for vim in ~/.vimrc) try the following:

  • Open a Python file with vim
  • type the following command :syntax on

You should now have VIM properly highlight your Python file.

To avoid having to re-type those command over and over again, I would suggest you keep a configuration file for VIM. This is usually located in your home directory, if there is not one there already, create a ~/.vimrc file and add the syntax on directive there to have VIM automatically highlight your Python files.

If you need to know more about structure/installation of plugins, then Senthil's answer is better suited :)

like image 82
alfredodeza Avatar answered Sep 23 '22 08:09

alfredodeza


You will find that you have a folder by name .vim in your home directory cd ~ and it will contain the following directories

ftdetect/  ftplugin/  plugin/  syntax/

You need to download the plugins and install them (copy them) to those directories.

Apart from that, in your .vimrc file have the following lines which will enable you to write python programs following PEP8.

set autoindent
set tabstop=4
set expandtab
set shiftwidth=4
filetype indent on 

There are some good documentation out there as well.

like image 29
Senthil Kumaran Avatar answered Sep 19 '22 08:09

Senthil Kumaran