I've been struggling with this topic for a little more than i'd like to admit but here it is:

I've set my vim (~/.vimrc) to indent using 4 spaces using

:set expandtab
:set tabstop=4
:set shiftwidth=4

Whenever I want to detete one of these groups I have to remove every one of the spaces. I thought vim would recognize this and remove them all like they were a single tab. Could anyone shed some light?

thks in advance :3

  • 1
    Note that there exists another workflow: I prefer to leave vim indent by itself (in C++ it's possible at least). And when I really need to change the indentation manually, I use either << and >> in normal mode, or CTRL-D and CTRL-T in insert mode. In the end, I never need <BS> nor <del> to remove &sw leading space characters. Jan 29 '18 at 12:16

You may prefer either or both of the following options:

set smarttab
set softtabstop=4

The primary difference between these two options in your case (where expandtab tabstop=4 shiftwidth=4) is whether the "backspace deletes 4 spaces" behavior works only at the beginning of lines (as with smarttab only) or everywhere, aligning to tab stops (as with softtabstop=4). For other values of expandtab, tabstop, shiftwidth the behavior is much more complex.


The other choice is to just use '<<' or '>>' to shift the line left or right. That should give you exactly the behavior you want from anywhere on the line. You can of course delimit a group of lines by moving to an opening or closing '[', '(' or '{', and doing '<%' or '>%' to shift a range of lines.

Of course other movement types work as well:


and others.

  • 1
    Or you could use ctrl-t and ctrl-d in insert mode. (see :help i_ctrl-t and :help i_ctrl-d)
    – Octaviour
    Jan 30 '18 at 17:27
  • Thanks for this tip, @Octaviour! :)
    – Dee'Kej
    Nov 11 '19 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.