Indenting with tabs vs spaces

Kaden sfam at mailandnews.com
Thu Nov 22 14:46:07 EST 2001


On 22 Nov 2001 00:32:05 -0500, David Bolen <db3l at fitlinxx.com> wrote:

> For example, Python mode in emacs will auto-indent a line on tab, but
> if it guesses wrong, a single backspace will step back a full
> indentation level (4 spaces) so it can still be very efficient to key
> in even though spaces are being used.

The following will do the same type of thing you describe (and more) if
you use vim:

set expandtab       " expand tabs out to spaces
set sw=4            " shiftwidth set to 4 spaces
set tabstop=4       " indent 4 spaces per tab
set softtabstop=4   " BS and DEL see multiple spaces as a tabstop
set bs=2            " allow backspacing over everything in insert mode
set ai              " always set autoindenting on
set list            " visualize whitespace
set listchars=tab:»·,trail:· " show spaces as · and tabs as »·

" Whenever you type any of the words in the list, it will automatically
" set the cursor at the next indention level.
au BufRead *.py set smartindent \
     cinwords=if,elif,else,for,while,try,except,finally,def,class

Of course you could change all these to only take effect when editing a
python file, as the last example does, if you don't like tabs expanded or
tabwidths of 4 chars in your regular text.

One argument I hear from advocates of tabs in source is that it's
difficult to see if one line's indention is off by just one space.
That's what the list and listchars lines help with.  For each tab you
should see two of those arrows and three dots.  If you don't, something's
not lined up right.




More information about the Python-list mailing list