Remove a single space at the beginning of the line, not four

If I have a code like this:

if (a == b) {
    // before
}

and the cursor is before the first slash, how is it possible then to remove just a single space, not four?

if (a == b) {
   // after
}

Another example. I need to reduce the indentation of line 2 from 8 spaces to 6.

if (a == b) {
    line 1
        line 2
    line 3
        line 4
        line 5
    line 6
}

It sounds like maybe your editor is using tabs rather than spaces? Or perhaps it’s using spaces, but it realizes that you’ve deliberately indented it for coding reasons and it’s assuming you want to outdent rather than have code indented 3 spaces?

Which editor is this?

1 Like

There’s a tag “xcode” attached to the question, so probably Xcode?

2 Likes

Speculation, and perhaps you’re already aware of this.

In Xcode the indentation can be set to prefer spacers or tabs. And the indent width can also be set to N spaces. So, it indentation was set to prefer tabs, and the tab width is set to 4 spaces, then when you backspace it will remover the tab.

1 Like

@webwalrus @MevetS

Xcode is configured to use spaces, not tabs:

Like in many other IDEs and text editors, if you press the Delete key at the beginning of the line indented with spaces, it deletes not just a single space, but the number of spaces corresponding to a single indentation level.

That is, pressing the Delete key at the beginning of indented line simply un-indents that line, which means that in such a case it works the same as if you have pressed Command-[.

In Sublime Text, for example, it can be turned off by using the following setting:

"use_tab_stops": false

I’m looking how to turn this off in Xcode.

That is, when I press Command-], it should add 4 spaces. And when I press Command-[, it should remove 4 spaces. But when I press Delete at the beginning of the indented line, it should remove 1 space, not 4.

Okay, here is the solution, by HangarRash on Stack Overflow, for the third example:

Move the cursor to column 6 and press fn-delete twice.

That’s it.

And here is an excerpt from https://support.apple.com/102650:

Fn-Delete: Forward delete on keyboards that don’t have a Forward Delete key. Or use Control-D.

Nevertheless, if someone has a better solution, let me know.