Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I edit Python code with Vim.

With the tab key I get four spaces inserted for indentation. How can I delete those spaces with one "Backspace"(?) stroke - instead of four?

There has to be some "set" option for that...

Here is my .vimrc:

set autoindent
set ts=4
set sw=4
set et
share|improve this question
up vote 17 down vote accepted

You can use Ctrl+D to back up one tab stop. This actually moves the whole line to the left one tab stop; Ctrl+T does the same thing to the right. Note that these keystrokes only work in Insert mode (use << and >> for the equivalent in Command mode).

share|improve this answer
this works!!! thanks. – Evgeny Jul 16 '09 at 3:22
set softtabstop=4
share|improve this answer
IMO this is exactly what the OP asked for. Deserves more upvotes. – Ludwig Weinzierl Jan 9 '12 at 7:06
This is the correct answer. – Mk12 Jul 30 '12 at 18:09
Did not know about this, and this was exactly what I was looking for. +1 – NigoroJr May 12 '15 at 19:46

I wrote GreedyBackspace.vim for someone who wanted something like this. I don't personally use it so it's been a while since I've updated it. I haven't received any bug reports on it lately, though.

share|improve this answer

Several options:

  1. You could 'retab' all whitespaces so they're replaced with tabs. That way they could be easily deleted.
  2. You could (this is untested, so I'm just proposing ideas here) make a function which 'execute's in normal mode 4 times the backspace key. Then map it to something. However, it has no way of knowing whether it will delete spaces or some important characters, so this is potentially unsafe.
  3. '4X' will delete the last 4 characters (that's big X, not small, small one will act like the Del key'.
share|improve this answer

easiest way is <<, repeat with a .

share|improve this answer
Hello and welcome to superuser. Although i agree with your answer being a vi user myself. Your answer is short, does not explain why you suggest what you are suggesting and why you are not suggesting something that fits the question asked. – Mogget Apr 3 at 21:50

Have you checked using the expand tabs setting in your VIM?

:set noet

I usually prefer keeping the tabs on while working on the files.
When it is required, I replace the tabs to 4 spaces or as many as required.

:%s/<ctrl+V><tab>/    /g

As a small bonus, your source file is shorter by 3 chars per tab :-)

share|improve this answer
oh, I have et because I have to expand tabs - i think - because code I edit was initially written that way. now I'm just following that convention. – Evgeny Jul 16 '09 at 3:20
You could still do what i say and restore spaces at the end (when you have to give the file back to the repository) – nik Jul 16 '09 at 3:24
Maybe you could have a vim function that expanded them to tabs on open and collapsed them to spaces on closing? Anyone have any ideas? – sixtyfootersdude Feb 23 '10 at 16:33
This is a really unhelpful answer--it needlessly reopens the tabs-vs-spaces debate, without actually providing any useful information. – Dietrich Epp Nov 24 '15 at 19:01

I don't think there's a way. Once the tab key is expanded to four spaces, vim has no way of knowing they were ever a tab.

share|improve this answer
-1: Lack of imagination. – sixtyfootersdude Feb 23 '10 at 16:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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