Tabs and indents settings does not work

Hello,

I have a problem with tab and indents settings. In settings->codestyle->php->tabs&indents I have set tab character for indent. But when I push tab button it uses 4 spaces instead of tab. Also some files works properly with tabs and some files not.

Could you help me please?

22 comments
Comment actions Permalink

Hi there,

1) If you have EditorConfig plugin installed .. and have .editorconfig files in your project (or maybe even folders above) .. such settings will be used from that file (if present there, of course) ignoring IDE settings (that's the actual idea/nature of this plugin)

2) Maybe you have "Detect and use existing file indents for editing" option enabled (Settings/Preferences | Editor | Code Style) .. and your file has an indent made with spaces somewhere on the top. Try it in brand new empty file -- does it work there?

22
Comment actions Permalink

Yes "Detect and use existing file indents for editing" was checked. Thank you very much. Have a nice day.

1
Comment actions Permalink

@Andriy

 

I'm having the same issue as above but I don't have that box checked. I also don't have the EditorConfig plugin installed or enabled.

I believe all my settings are correct, but no matter what when I create a new line in any PHP file it adds it with spaces (when I want it to do so with tabs).


1
Comment actions Permalink

Your screenshots look absolutely fine.

Right now I do not know what else it might be.

I found this ticket: https://youtrack.jetbrains.com/issue/WI-32698 -- not sure how relevant it is for your case. Maybe other tickets.. but I personally not aware of them (I'm not associated with JB)

Right now I may suggest to try something among these lines:

  • Make sure that whole file uses correct indents (select all text and choose "Edit | Convert Indents")
  • Save and Close file
  • Ensure that indent settings are fine
  • Open file again and try writing some code that would produce indents
  • See how it will behave

 

 P.S. Right now I can reproduce this:

  • Have PHP file with space indented
  • Go to Settings and change indentation to Tab
  • Go back to file and press Enter so it creates new line (e.g. after opening { in function definition)
  • New line will have mixed Spaces (first 4 characters) and then 1 Tab
  • (NOTE that I do have "Detect..." and EditorConfig plugins enabled .. but no actual .editorconfig files though)
1
Comment actions Permalink

BTW -- try with fresh Code Style schema (e.g. Default) and modify it. Will it be any better?

1
Comment actions Permalink

RubyMine 2007.1 shows error markings around all indentation tabs?

0
Comment actions Permalink

Ehud Pardo, I would suggest opening a new thread at RubyMine forum.

0
Comment actions Permalink

Issue resolved, it was due to RuboCop inspection, in RM-2017.1

 

0
Comment actions Permalink

The problem is still happening on RM-2017.1, but I found a solution for my situation.

 

I'm using it for Wordpress development, and as it mixes php with HTML content, I had to set both PHP code style and HTML code style to HTML.

It was also happening on files with no HTML.

5
Comment actions Permalink

I'm having the same problem, but with JSX in Rubymine. None of these suggestions seem to work for me. Any other ideas?

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000433590-Codestyle-for-JSX

0
Comment actions Permalink

Perhaps there is a .editorconfig file in the project. The settings in .editorconfig override the Code Style settings in the preferences.

1
Comment actions Permalink

I also have the same issue. I don't have an .editorconfig file or the editorconfig plugin installed, I replaced all my spaces with tabs and I have "Detect and use existing file indents for editing" option disabled and still get spaces instead of tabs

0
Comment actions Permalink

@Javier - please attach screenshots that would illustrate the issue + screenshots of your code style settings

0
Comment actions Permalink

I'm having the same issue, clean install of PHPStorm on an existing project. No .editorconfig file or editorconfig plugin install. Settings screens attached as well as a screenshot of the spaces when I hit enter after the function opening brace. 




2
Comment actions Permalink

It's also doing this weird thing where it uses a tab for the first indent and then 4 spaces for the 2nd indent (screenshot attached)

0
Comment actions Permalink

@Jonathan Bossenger

In your case it could be because of:

  • Smart Tabs option -- just try disabling it to see if it will make any difference (close and re-open project for more reliable behaviour)
  • Some previous content in that file (e.g. lots of HTML -- this file might not be pure PHP (one PHP block for whole file) and may have blocks of HTML (I'm not referring to HTML strings like on screenshot -- it's about actual HTML block or perhaps HEREDOC/NOWDOC))

No better ideas right now.

1
Comment actions Permalink

@Andriy Bazanov thank you that was it, the file had some HTML in it and my HTML indents were spaces, switched that to tabs as well and its working, thank you.

Just another good reason to separate presentation from logic.

0
Comment actions Permalink

@Dmitry Tronin Sorry for the late response. I can also confirm that the problems with tabs and indents were caused by non-pure php files that contained HTML. I was developing some stuff in wordpress when this came up and it's more common to find there mixed php and html. 

0
Comment actions Permalink

Right now it might be worth watching this ticket (to see what devs will say): https://youtrack.jetbrains.com/issue/WI-35370 or even https://youtrack.jetbrains.com/issue/WI-32401

At the same time -- see https://youtrack.jetbrains.com/issue/WI-17786 where it was asked to have it that way (as far as I understand).

 

From my end I may only say this: keep (big?) HTML chunks of code in separate files, templating system (like Twig or alike) or properly escaped -- do not mix them; or maybe just use the same indent settings.

0
Comment actions Permalink

Also make sure you arn't working in a file which has a specific setting set in Settings -> Editor -> Code Style.

For example; I was working in a .less file and thought the css/global code style settings were leading for this. I was breaking my head over why the file was using 2 spaces as indentation when I entered 4. Then I found that less has it's own code style under Settings -> Editor -> Code Style which uses 2 spaces in the settings..

0
Comment actions Permalink

In Editor>Code Style I changed my Scheme from "Project" to "Default" and it fixed the issue.

0
Comment actions Permalink

In my case problem was in unchecked "Smart indent" checkbox in 'Editor > General > Smart Keys'. When it is checked autoindentation works correctly according to Code Style settings.

0

Please sign in to leave a comment.