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 t开发者_StackOverflow社区o 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).
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/
精彩评论