PhpStorm 2017 is eminently configurable. You can adjust more or less any aspect of the IDE. In particular, the user interface (UI) can be very finely tuned to fit your needs.
Sadly, the way settings work can turn you crazy. The are no less than three ways to tune the settings at any time :
- at the welcome screen, the Configuration button, then Settings ;
- if a project is opened, the File menu, then Settings ;
- if a project is opened, the File menu, then Default Settings.
Moreover, in some cases, a setting may be tuned by telling PhpStorm that its value should be related to a “profile” ou a “scheme”…
The main problem with settings in PhpStorm is that the entry point for tuning settings does not talk to the user. How to tune a setting and apply the new value to a set of projects ? How to tune a setting so that the new value should only apply to projects to come ? The user has to work it by himself to find answers to such basic questions.
Since nobody ever published a good in-depth explanation about how settings do work in PhpStorm 2017, let’s explore the possibilities of PhpStorm 2017.3 to understand how all of this may be achieved.
Ciquez ici pour lire cet article en français.
What is a setting in PhpStorm 2017 ?
Let’s start by clarifying the notion of setting. The are two types of setting :
- those that apply to the IDE ;
- those that apply to projects.
For example, the settings in Editor / Font do apply to the IDE, and those in Editor / Code Style do apply to projects (you can guess it because of the small icon on the right).
In PhpStorm 2017.3, settings that apply to projects are grouped in various categories, including Appearance and Behaviour, Editor and Version Control.
Some tests to guess how settings do work
Start PhpStorm 2017.3 for the fist time (you don’t need to reinstalle PhpStorm 2017.3 for that ; just delete the contents of C:\Users\<user>\.PhpStorm2017.3). Choose “Darcula” to avoid tiring your eyes and tell PhpStorm that it should use the default settings.
In the welcome screen, click on Configure and select Settings.
Navigate to Editor / Code Style / PHP. The selected scheme should be Default.
Check Use tab character and set Tab size to 8. Notice that two folders are created in C:\Users\<user>\.PhpStorm2017.3\config:
-
A codestyles folder containing a Default.xml file. As expected, this file contains both settings values:
<option name="TAB_SIZE" value="8" /> <option name="USE_TAB_CHARACTER" value="true" />
-
A options folder containing a bunch of files, among which a code.style.schemes file. This file contains this line:
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
Go back in Editor / Code Style / PHP. Select the Project scheme.
Use tab character is not checked and the value of Tab size is 4. Check Use tab character et set Tab size to 16. The code.styles.schemes file in C:\Users\<user>\.PhpStorm2017.3\config\optionsis updated as follows:
<option name="PER_PROJECT_SETTINGS"> <value version="173"> <codeStyleSettings language="PHP"> <indentOptions> <option name="TAB_SIZE" value="16" /> <option name="USE_TAB_CHARACTER" value="true" /> </indentOptions> </codeStyleSettings> </value> </option> <option name="USE_PER_PROJECT_SETTINGS" value="true" />
Go back in Editor / Code Style / PHP and just select the Default profile. Once again, the code.styles.schemes file is updated to reflect the selected scheme:
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
Create a new project starting with an empty folder, and add a new PHP file to it.
In the editor, pressing the Tab key does insert a 8 characters wide tabulation character. This means that the Default profile is active, as it could be expected.
The folder of the project does contain a .idea folder. In this folder, there is a codeStyles subfolder. This subfolder contains two files:
-
codeStyleConfig.xml, which tells that the settings in the Default scheme should apply to Code Style category :
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
-
Project.xml, which contents we have already met since it comes from code.styles.schemes:
<codeStyleSettings language="PHP"> <indentOptions> <option name="TAB_SIZE" value="16" /> <option name="USE_TAB_CHARACTER" value="true" /> </indentOptions> </codeStyleSettings>