Introduction
I do a lot of Symfony PHP development, and I use Eclipse as my IDE. I’ve been using Eclipse for many years, so I don’t want to switch to PHPStorm, even though it’s one of the most popular IDEs used with Symfony and PHP development.
This article is about a problem of auto indentation when using Eclipse to edit code.
The Problem
The problem I experienced, was when I was cutting and pasting a variable in a foreach
loop or in a variable definition, the IDE would automatically remove the space(s) to the right of where I pasted.
For example, let’s take this example code:
foreach( $bad as $val ){
Then I would double-click the “$bad
” variable and do a paste and paste “$employ
”, and the IDE automatically deletes the space right after “$employ
” and the “$employ
” and “as
” combine. So it ends up looking like this:
foreach( $employas $val ){
So you should realize the problem. What it is trying to do is auto indentation.
Fixing the Problem
Regardless of whether you are using PHP or C++ or another language, you would do the same thing. In Eclipse, do the following steps:
- Select Window > Preferences.
- In the Preferences dialog, select PHP (or language you need to change) > Editor > Typing.
- In the Typing area and “When pasting” group, uncheck “Adjust indentation”.
- Click Apply.
Below is a screenshot for reference: