My VIM .vimrc file for working with Python

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.

Related

This entry was posted in Python and tagged , , . Bookmark the permalink.

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. Selinap says:

    @Hadi: Python is an interpreted programming language that runs on Windows, Linux/Unix, Mac OS X.

  4. Selinap says:

    @Eric Wendelin: I am glad to hear that.

  5. Hadi says:

    What is the use of writing programs in this language instead of using other programming languages or scripting languages?
    Is it faster? Is it specific for some topics?

  6. Paddy3118 says:

    http://www.python.org is a good place to read for answers to your queries!

    - Paddy.

  7. Selinap says:

    @Paddy3118: You are absolutely right.

  8. 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).

  9. Selinap says:

    @David: Thanks. I will have a look.

  10. 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

Your email address will not be published. Required fields are marked *

*

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