简体   繁体   中英

How to align code, in PhpStorm / Intellij, using tabs (and not spaces)

I'm trying to setup PhpStorm, so I can simply press: "Reformat Code" ( Option CMD L ), before each save - and then it'll make everything look right.

But I have this case, where I don't know how to make PhpStorm make the code right.

This is the code:

对齐字符错误

As you can see, then indentation is with tabs, but the aligning of the characters are with spaces.

I want it to look like this:

右对齐字符

It would be cool to get the solution. But it would be even cooler to be able to figure out, how I could have found the solution myself.

Further info / idea: There is a Php Codesniffer from Squizlabs implemented. So I can fix is automatically by running a sniff fix -command. It would be pretty cool, to be able to automatically setup PhpStorm's Code style settings, to correspond with Squizlabs styles, without having to gradually tune the settings one thing at the time. But I haven't found that functionality.


Solution attempt 1: Read through all Settings >> Editor >> Code style >> PHP

I couldn't find anything that resembled this.

Solution attempt 2: Disable .editorconfig

I've read quite a bit about .editorconfig and it doesn't have these nitty-gritty functions here (as aligning equal signs).

But to make sure, I tried disabling it. Didn't make a difference.

Solution attempt 3: Search setting for 'align' and 'formatting'

But I didn't find anything useful. :-/

Solution attempt 4: Update PhpStorm

I was on PhpStorm version 2022.2.1 .
I tried updating to PhpStorm version 2022.2.4 .

This is still in progress.

Please show what you have at Settings (Preferences on macOS) | Editor | Code Style | PHPSettings (Preferences on macOS) | Editor | Code Style | PHP Settings (Preferences on macOS) | Editor | Code Style | PHP , specifically Tabs and Indents tab.

Checking Use tab character option with unchecked Smart tabs should do just that.

https://www.jetbrains.com/help/phpstorm/2022.3/settings-code-style-php.html#php-specific-formatting-settings-for-tabs-and-indents

PhpStorm 代码风格 |制表符和缩进
( Pro tip: you can copy-paste your code sample in the preview area and start changing the options; the IDE will apply the changes live on the provided code sample instead of the default one. )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM