How to get VIM indentation and Python playing nicely?

Ryan Paul segphault at sbcglobal.net
Sun Jun 13 20:32:41 EDT 2004


On Sun, 13 Jun 2004 22:28:07 +0000, Kenneth McDonald wrote:

> I've just started to use VIM as a Python editor. However, getting
> indentation to work nicely is giving me fits. I've tried a bunch
> of different settings--shiftwidth, ts, etc etc.--to get tabs
> working the way I want, but can't get things quite right. I'm
> hoping some of you python/VIM users can help.
> 
> Here's what I want:
> 1) A tab displays in a width equal to four spaces.
> 2) <tab> always produces a tab char; it does not substitute spaces.
> 3) <del> (in edit mode) always deletes the previous character;
> it doesn't do anything fancy.
> 4) <ret> (in edit mode) produces a new line below with the
> same leading whitespace as the previous line _unless_ the 
> previous line ended with ':', in which case an additional
> tab character is added.
> 
> Here's what I'm getting (settings are shiftwidth=4, ts=4, 
> every other tab-related setting that I can find that was
> 8 is four, and I've tried lots of other stuff at the same
> time, such as notabexpand). Not all of this happens all
> the time, but at least one of these behaviors happens no
> matter what settings I've tried:
> 1) <del> dedents by 8 spaces: ^D dedents by 4 (which is what
> I want.
> 2) <tab> sometimes indents by 4, and sometimes by 8, at
> different places in the same file _using the same settings_.
> 3) Typing a ':' can cause the entire line (including what
> has alrady been typed) to dedent or indent. In my view,
> this is a very bad no-no.
> 
> Hopefully the solution to this sort of thing is easy. If
> not, then I guess the search for an editor resumes...
> 
> 
> Thanks,
> Ken

Do you have the ft plugin enabled with support for python filetype? You
might want to enable autoindent or smartindent. Also, look and see if your
distribution is setting any stupid defaults. I remember redhat used to set
a bunch of wierd stuff at the site level, and I had to su to root and get
rid of it. You might want to read ':help autoindent'.

Vim takes a lot of time and patience to learn. You would probably benefit
from reading section 5 of the user-manual ('Set Your Settings').

Good Luck

--segphault




More information about the Python-list mailing list