0

I use Netbeans 8.2 for PHP coding for a long while. Now I set it up again on a new laptop and I'm again stuck with disabling the smart-indentation. I can't find any option within Netbeans nor some hint on the web.

My goal: I need the auto-indentation (insert tabs after newline), but not the "smart" indentation, that sometimes eats tabs at the beginning of the line.

Example:

I type the following in the editor (the pipe | is the caret):

<div>
    <?php if(true) { ?>
        <div|

    <?php } ?>
</div>

When I now type the closing >, the smart indentation do a back indent on the line:

<div>
    <?php if(true) { ?>
    <div>|

    <?php } ?>
</div>

And that's the annoying behaviour I try to disable.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
g4rf
  • 11
  • 7

1 Answers1

0

I'm not entirely clear on what you mean by "smart" indentation so this might not rise to the level of an answer, but in any case it's too big for a comment, and it may point you in the right direction.

To adjust your indentation settings for PHP code on NetBeans:

  • Select Tools > Options > Editor
  • Click the Formatting tab.
  • Select PHP from the Language drop list, and Tabs and Indents from the Category drop list.
  • Uncheck the Use All Language Settings check box.
  • You can then play with the settings for various fields, and see how your changes impact the sample code displayed on the right side of the Options screen. For example:

    PHP tabs and indents

  • Click the Apply button to implement your changes.

Notes:

  • You might want to take a screen shot of the Tabs and Indents screen before making any changes so that you can revert to the default settings if necessary. There is no Revert to Defaults button.
  • After making your changes to the tab and indentation rules you can leave the Options window open, and reformat your own code using Alt + Shift + F. If you don't like the results just undo the changes to your code (Ctrl + Z), refine the settings on the Options screen and reformat again.
  • I couldn't get line wrapping to work after adjusting the Right Margin value with Line Wrap set to Anywhere. I think there may be a bug.
  • There are several other options available on the Category drop list (Alignment, Braces, etc.) if you want to further override the default formatting rules for PHP.
  • Whenever changing the code formatting rules:
    • Be mindful that this may result in a huge number of line changes within your source control system, so never combine code changes with non-trivial formatting changes.
    • In a team environment make sure everyone is using the same formatting rules.
skomisa
  • 16,436
  • 7
  • 61
  • 102
  • Thanks for your suggestions. I know this options page and played around a lot. But there is no way to achieve my goal. I added an example to my post to make it more clear. – g4rf Jul 05 '19 at 06:30