views:

37

answers:

1

I'm using Vim for Python development. Sometimes, after an expression in an if clause: (suppose | is cursor).

if test:
    pass
    |

...I press enter, and want to go to the if identation level.

I know I can go back to command mode and just press <, but I would like to know if it's possble to, when Vim knows all characters behind the cursor are tabs os spaces, to go back one indent level when backspace is pressed (or shiftwidth value).

+2  A: 

Set softtabstop equal to shiftwidth, and turn on expandtab:

:set expandtab shiftwidth=4 softtabstop=4

Now when you press Backspace, Vim will automatically delete the proper number of spaces to move back one indentation level.

There are several settings that control the behavior of tabs, spaces, and indentation, and they can interact in non-obvious ways. I recommend this Vimcast episode for a very clear overview:

http://vimcasts.org/episodes/tabs-and-spaces/

Bill Odom
+1 for mentioning the awesome vimcasts.
jeffjose
+1, it works. Just another thing: I already had all these commands in my vimrc, but not called at the same time as you suggested. Is there something I'm unaware of in this situation?
Somebody still uses you MS-DOS