18

I have replaced all my tabs by spaces in my PHP code source (and I configured Eclipse to use 4 spaces as tabs). When I hit tab, I get 4 spaces, that's OK.

But when I hit backspace to remove an indentation level (a tab), it removes only one space. So I have to hit 4 times space to remove an indentation level.

That is one of the most absurd thing I've seen in Eclipse, so I guess there is an option somewhere to enable us to remove 4 spaces as if it where a tab ? or a plugin ?

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
  • What's so practical about spaces? I doubpt that there is andoption to tell Eclipse how many spaces should be removed when user presses Backspace or Delete – Riho Mar 31 '10 at 08:47
  • The only reason I can see for space indenting is that I like to use to spaces as it stops the code running of the right hand side whilst still being 'properly' indented. If you want sapces for indentation, use spaces for indentation. tabs are there for big indents, and I don't think any one has set a "1 tab = x spaces". – thecoshman Mar 31 '10 at 08:50
  • I use space because this is the standard in PHP. So I wont change, there are reasons. And Eclipse let me specify how many spaces are used for indentation, so why use that for indenting, and not use that for "de-intending" ? – Matthieu Napoli Mar 31 '10 at 08:55
  • As far as I know, no language has a 'standard' indent. There is convention, but that is not same as standard. The reason for the auto-indent, is that normally, you will start at the same place on the next line, or if opening a code block, start one indent further in. A good IDE should indent one less automatically for you. it should also have buttons at top to let you highlight a section of code and add/remove units of indents. – thecoshman Mar 31 '10 at 08:59
  • 1
    raaaaahh you obviously are not a PHP developper. OK so let's not talk about it anymore. But this is simple : when I hit tab, I get 4 spaces, then I hit backspace, it removes only 1 space. I have configured Eclipse to use 4 spaces as tabs. – Matthieu Napoli Mar 31 '10 at 09:09
  • Ignoring the obnoxious. The tab key on your keyboard inserts a special 'tab' character (ASCII character 9). Ecplise is noticing you typed that character, but rather then writing a tab, it is writing X spaces (ASCII character 32), rather then an actual 'tab', which as far as I know, is just defined as more then a space. When you press a characters such as back space (ASCII 8), you are telling eclipse to remove one character from the left of where the carrot currently is. Eclipse is simple not checking if that is a normal space characters, or a super special 'converted from tab space' – thecoshman Mar 31 '10 at 09:17
  • 1
    You are explaining me why it doesn't do what I want (btw I knew but thanks you never know). I am asking how to do what I want. This is maybe one of the most basic and simple functionnality to implement, so I wonder wether it exists, or if a plugin exist. I guess I'm not the first to want that, as 90% of PHP developpers use spaces as tabs. – Matthieu Napoli Mar 31 '10 at 09:27
  • @Matthieu: your question is actually formulated as "how can spaces behave as tabs", which I interpreted (at least initially) such that you were wondering why Eclipse behaves as it does. – JesperE Mar 31 '10 at 10:24
  • Well, it works as you wished in PyDev (Python IDE for Eclipse) so maybe you should talk to authors of PHP IDE for Eclipse? – Piotr Dobrogost Nov 12 '11 at 20:21
  • That might be possible with [Eclipse 20199.12/4.14](https://stackoverflow.com/a/58344908/6309)! – VonC Oct 11 '19 at 16:05

4 Answers4

6

Don't think there is a way to set it to delete the entire space indentation with backspace, but shift+tab should do what you want.

Tjkoopa
  • 2,298
  • 1
  • 17
  • 20
  • 2
    Yes you're right, but as you may feel to, I greatly prefer to have this behavior with backspace to (for example when deleting code, and in the continuation you delete indentation, you don't want to change of key). Isn't there a plugin for that ? How PHP developpers do, its almost giving me nightmares, I now hate Eclipse for that. – Matthieu Napoli Mar 31 '10 at 09:32
  • Why don't you just bind Backspace to "Shift-Left", then? (Personally I like to have Eclipse do a full source file format on save (according to the formatting rules), which saves me the brain-ache of maintaining proper indentation.) – JesperE Mar 31 '10 at 10:26
  • 1
    If I do bind backspace to "Shift-tab", I will mess with the initial behavior of the backspace key and I wont be able to erase anything (well I guess it will do that). I just dont understand how such a basic functionnality isn't possible in this really advanced tool. – Matthieu Napoli Mar 31 '10 at 13:49
6

After all this time, no solution.

I'm considering this as impossible then : there is no solution.

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
3

So... I also need that feature. Before a began to use Eclipse, I was a Vim user. Actually a still use it for some edit task. There is a vimplugin for eclipse, so you can use it as your Eclipse editor. But its a matter of taste.

You can configure vim to do exactly that: Tab insert 4 spaces. Backspaces deletes indentations.

Here the config for your settings:

set tabstop=8       " This is the default in any editor, Tabs are 8spaces Wide"
set expandtab       " Tabs are converted to spaces"
set softtabstop=4   " Tabs are 4 spaces"
set shiftwidth=4    " Indent is 4 spaces"
" Here the magic"
set backspace=indent,eol,start  " Deletes over indent, line breaks, edit starts"

HTH

Asturio
  • 31
  • 1
1

9+ years later, space will behave as tab when it comes to deletion.
With Eclipse 4.14 (part of the Eclipse 2019-12 simultaneous release, available December 18, 2019), you can use delete spaces as tabs

See "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.

https://www.eclipse.org/eclipse/news/4.14/images/delete-spaces-as-tabs.png

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @bigstones And thank you to the one(s) who actually has/have implemented this feature! – VonC Jan 16 '20 at 10:14