20

Having eclipse configured to use space instead of tabs, is it possible to configure eclipse so that the backspace key unindents like the tab key indents?

A demonstration to clarify what I mean with backspace unindent (the vertical bar stands for cursor position and the dots for spaces):

if(bar == 0) {
|foo = 0;
}

Pressing tab will indent 4 spaces:

if(bar == 0) {
....|foo = 0;
}

Pressing backspace only goes back 1 space:

if(bar == 0) {
...|foo = 0;
}

What I want is that it goes back 4 spaces:

if(bar == 0) {
|foo = 0;
}
Lesmana
  • 25,663
  • 9
  • 82
  • 87
  • That might be possible with [Eclipse 20199.12/4.14](https://stackoverflow.com/a/58344908/6309)! – VonC Oct 11 '19 at 16:04

4 Answers4

9

You know that "shift+tab" will outdent a line already, correct?

Hmmm, I just took a look at preferences->general->keys. I only see indent line there, no outdent (or anything useful under "dent").

Personally, I would say that backspace is the key I hit second most often, after space. Rebinding it would drive me bonkers.

7

According to these very similar questions:

it seems to be not possible :(

Community
  • 1
  • 1
Lesmana
  • 25,663
  • 9
  • 82
  • 87
3

Hard way: set Eclipse to format indention using the tab character. Then backspace will remove the tab char

Easy way: start using the formatting feature of Eclipse to fix the formatting. Ctrl-Shift-F will format the selected lines or the whole file if there is nothing selected, using the formatting rules you configure.

Alternative: select the lines of text you want unindented and use shift-tab, it will unindent the selected lines.

Kelly S. French
  • 12,198
  • 10
  • 63
  • 93
3

The feature will finally be available for next version of Eclipse 4.14 planned for 2019-12 https://www.eclipse.org/eclipse/news/4.14/platform.php#delete-spaces-as-tabs

Backspace/delete can treat spaces as tabs If you use the Insert spaces for tabs option, now you can also change the backspace and delete keys behavior to remove multiple spaces at once, as if they were a tab. The new setting is called Remove multiple spaces on backspace/delete and is found on the General > Editors > Text Editors preference page.

Sylvain K.
  • 56
  • 3
  • The Eclipse version 4.14 is released now – Sylvain K. Dec 20 '19 at 14:03
  • Checked this setting but it does not work for me (Eclipse Platform 4.20, Eclipse CDT 10.3). At the top of the config pane it states "Some editors may not honor all of these settings". Maybe C/C++ Code Style Formatter in CDT overwrites/ignores this setting? – Daniel K. Mar 08 '22 at 08:50