1

I asked another question yesterday but this bothers me a little. I use 4 spaces as indentation for programming (ShellScript, C and Python, mostly). When I want to delete the 4 spaces, I had to do one by one. When I was using vim, I didn't have to do in that way.

What I want to set up is that, when you put the cursor at the beginning of the first word after indentation and press DEL, it deletes the 4 spaces at once.

An example:

int main () {
    ▮int a = 0;
    if (a = 0) {
        printf("Hello!");
    }
    return 0;
}


int main () {
▮int a = 0;
    if (a = 0) {
        printf("Hello!");
    }
    return 0;
}

(Suppose that ▮ is with the i).

Is it possible to do that in emacs?


Result of doing C-u C-x = on the indentation:

enter image description here

1 Answer 1

2

I have tested in emacs -Q that C-u <backspace> will delete 4 spaces backwards.

Equivalent bindings would be:

  • M-4 <backspace>
  • C-4 <backspace>

Before

int main () {
    ▮int a = 0;

(▮ represents point)

Do C-u <backspace> or C-u DEL.

After

int main () {
▮int a = 0;

By default C-u represents a repetition or 4 for most commands (usually navigation related).


Update

To delete 4 space to the right of the cursor, do C-u C-d instead.

Before

int main () {
▮    int a = 0;

(▮ represents point)

Do C-u C-d.

After

int main () {
▮int a = 0;

On emacs 25.1.50.x (emacs master branch as of now), <backspace> or DEL is bound to the backward-delete-char-untabify command by default.

12
  • I understand what you tell me, but I don't convert the spaces to TABs or viceversa in real time, I have changed it in the config for every indentation.
    – user11867
    Jul 22, 2016 at 15:20
  • Hmm, then I do not understand your question.. the question says "Kill 4-spaces .." Jul 22, 2016 at 15:21
  • From the cursor to the point of where the 4 spaces start. It's like treating 4-spaces as a unique tab, not converting it in real time to delete it.
    – user11867
    Jul 22, 2016 at 15:32
  • @captainepoch It's not clear if you are trying to delete 4 ASCII Space characters (0x20) or an ASCII TAB character (0x09). What do you see when you do C-u C-x = with cursor on the area that you call "4 spaces". Jul 22, 2016 at 15:34
  • I see this (I hope it's what you asked for, large image, that's why I didn't use MD's image syntax) i.imgur.com/3I4a2Ep.png
    – user11867
    Jul 22, 2016 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.