How to get VIM indentation and Python playing nicely?

Discussion in 'Python' started by Kenneth McDonald, Jun 13, 2004.

  1. 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
    Kenneth McDonald, Jun 13, 2004
    #1
    1. Advertising

  2. Kenneth McDonald

    Ryan Paul Guest

    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
    Ryan Paul, Jun 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWlrZQ==?=
    Replies:
    0
    Views:
    952
    =?Utf-8?B?TWlrZQ==?=
    Aug 31, 2005
  2. infidel
    Replies:
    2
    Views:
    430
    infidel
    Nov 14, 2005
  3. Daniel Folkes

    New to Vim and Vim-Python

    Daniel Folkes, Oct 24, 2007, in forum: Python
    Replies:
    3
    Views:
    538
    projecktzero
    Oct 25, 2007
  4. Jim Crigler
    Replies:
    2
    Views:
    160
    Ara.T.Howard
    Nov 2, 2005
  5. mathog
    Replies:
    7
    Views:
    236
    Martin Shobe
    May 31, 2013
Loading...

Share This Page