vim and tabs in Python code

Alex Martelli Alex.Martelli at think3.com
Fri Jan 28 10:57:55 EST 2000


Nicolas writes:

- The indentation is seen by the interpreter but not
  by me, e.g. a 4-blank tab is seen the same as 4 blanks
  but not interpreted the same. Hard to tell something
  invisible is different from something else invisible.

Right, which is why VIM (and Emacs, and other good editors)
make it easy for you to smooth this out.


- Whatever intelligence you put in vim, will not help
  other kinds of editors, will it?

Of course -- a bad editor remains bad.


> I would appreciate, though, if anyone could give an
> advice about how to configure vim or preprocess
> somebody else's code to make it fit any given convention
> for indentation.

Look into the expandtab, smarttab and softtabstops options
of VIM.

Setting expandtab, any tab you enter becomes the right
number of blanks; setting smarttab, the shiftwidth option
becomes valid also for a tab you press at line start;
softtabstop may make it more natural to erase (backspace)
over multiple blank spaces just inserted by hitting a tab --
or it may not, try it out and see how it works for you.

With :autocmd BufWritePre *.py retab, and similar settings,
you can also ensure that tabs are always eliminated (or,
always inserted!) when a file is written (or read, etc --
here, I've specified it for writing, and for Python source
files only, but it's easy to tweak this!).


Alex




More information about the Python-list mailing list