Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backspace, if chars from cursor to begin of line are tabs/spaces, go back one indent level

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).

like image 608
Somebody still uses you MS-DOS Avatar asked Feb 26 '23 15:02

Somebody still uses you MS-DOS


1 Answers

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/

like image 144
Bill Odom Avatar answered Apr 25 '23 09:04

Bill Odom