What's the canonical vi setting for Python indentation

Neil Schemenauer nascheme at enme.ucalgary.ca
Wed Dec 1 13:06:08 EST 1999


Quinn Dunkan <quinn at amatho.ugcs.caltech.edu> wrote:
>>On Tue, Nov 30, 1999 at 11:46:10PM +0000, Sean Blakey wrote:
>>> I don't know about canonical, but I have the following in my .vimrc
>>> set expandtab	"Turn's tabs into spaces
>>> set hardtabs=4	"Make tabs 4 spaces wide
>>> set tabstop=4
>>> set shiftwidth=4	"For use with << and >>

It is not really a good idea to change tabstop to a value other
than 8.  Use vim5 and softtabstop as Quinn suggests.  I used to
do it but have been reformed.  It works great if you are the only
one editing code and you don't have to edit files that use a
mixture of tabs and spaces.

>Here's my config:
>
>se et ts=8 sw=4 softtabstop=4 smarttab
>
>I like keeping tabs at 8 chars since many other things expect that.
>For indentation I use:
>
>se ai
>im :<cr>    :<cr><tab>

That mapping is really cool.  You should probably add expandtab
to your list of options.  If you only use sts then a tab will be
inserted for 8 spaces.  I think this gives about the same
behavior as python.el:

    :au BufEnter *.py set sw=4 sts=4 et ai

breaking that down:

    sw=4    " Use 4 spaces for << and >> (and other things)
    sts=4   " <Tab> inserts 4 spaces (but replaces 8 with tabs)
    et      " Expand all tab values to spaces
    ai      " Automaticly indent new lines

You don't have to worry about backspacing through 4 characters to 
remove an indent.  Vim is smart enough to delete sts chars.  You
haven't changed the size of tabs so if you open I file that
assumes ts=8 then everything will still look okay.

If you hate tabs and want to see them, this is useful:

    set list listchars=tab:··

If you use the above indentation setting you should be pretty
save anyhow. 

    Neil

-- 
"The percentage of users running Windows NT Workstation 4.0 whose PCs stopped
working more than once a month was less than half that of Windows 95 users."
  -- microsoft.com/ntworkstation/overview/Reliability/Highest.asp




More information about the Python-list mailing list