My VIM .vimrc file for working with Python

Thursday, October 1st, 2009
Advertisement

Subscribe.
Enter your email:

Here is the VIM .vimrc file that I use to work with Python.

set nu
set ts=4
set sw=4
set sts=4
set autoindent
set smartindent
set expandtab
set smarttab
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd BufWritePre *.py :%s/\s\+$//e

It will

  1. Display the line number.
  2. Set tab stop to 4.
  3. Enable you to use < and > to indent or unindent a block in visual mode.
  4. Insert spaces instead of tab, when pressing the tab button.
  5. Automatically indent the next line after this keywords: if, elif, else, for, while, try, except, finally, def, class.
  6. Remove all trailing spaces during exit.
If you are new here, you might want to subscribe to the RSS feed or newsletter.

Enter your email address:

Creates the exact copy of your hard disk and allows you to instantly restore the entire machine.
New Acronis True Image Home 2010 is the most reliable and easy in use backup solution. Now with online backup option!
15% Discount Code: FMAATIH2010

What else?

Like this article? Share it

 Digg  del.icio.us  TwitThis  Facebook  Reddit  StumbleUpon

10 Responses to “My VIM .vimrc file for working with Python”

  1. I’ve been meaning to try using vim instead of NetBeans for Python editing. You just gave me a bit of a boost. Thanks!

  2. Hadi says:

    What is the use of Python? I mean, what do you use it for?

  3. David says:

    Some tips here on an improvement to your setup, namely making it automatically indent up to the parens inside long argument lists (the way PEP8 says one should). The script is here, put it in ~/.vim/indent and remember to “set filetype indent on” (or “set filetype indent ftplugin on” if you use that other post’s ftplugin trick).

    • Selinap says:

      @David: Thanks. I will have a look.

    • Jonathan says:

      Also be sure to “set nosmartindent” as described in the recent update to David’s link. Keeping smartindent on if you have filetype indent support on is redundant, and only causes problems (e.g. shoves all comments to the left because it thinks they’re #include statements). Filetype indenting really is much nicer than smartindent, allowing its plugins to provide much more custom python (or whichever other language you are using) support instead of a generic set of hardcoded rules (like smartindent or cindent).

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>