In the settings window of Phpstorm, there is a dropdown box labelled scheme
What does it do?
What does it do?
You may be surprised .. but it allows you to choose another (different) Code Style scheme for this project.
PhpStorm supports globally defined schemas (by default it provides only one -- "Default") which can be used by any project and project-specific schema called "Project" which available for this project only (and stored together with other project-specific settings).
You can read more in official help page.
The Code Style is used for code formatting: be it automatic as you type / use live templates etc .. or manual reformat via Code | Reformat Code...
It's used to
choose the code style scheme to be used as the base for your custom coding style for the selected language (Source).
In other words: after selecting a scheme, you can set different formatting options, like tabs vs spaces, tab size or line breaks etc. To use those settings in your current project, you need to click Manage, select your edited scheme and click Copy to Project. After this, you can press Ctrl + Alt + L (Code > Reformat Code...) in the editor to reformat a file according to those scheme settings.
Related
How can I add a custom key shortcut (ie: ctrl-something) in IntelliJ / Android Studio, so that it will automatically add a custom snippet that I associated to that combination? Is there a way?
You can create a live template settings>Editor>Live Templates.
Choose your category, and click on the "+" sign. You can then choose the abbreviation, add variable using the $VARIABLE$ notation and the context (Java, XML etc..).
Now you can just type the abbreviation in the editor and auto-complete it (ctrl+space, tab) and your snippet will be written.
Whenever I hit alt-cmd-l to autoformat my code, it formats my imports and arrays from:
import { CommonModule } from '#angular/common';
let arr = [ myStringVar ]; // simple example, just go with it
to
import {CommonModule} from '#angular/common';
let arr = [myStringVar];
How do I tell IntelliJ to put a space after the opening brace and before the close brace when auto-formatting? (Specifically for javascript, typescript)
I've looked around for the answer and could not find one or asked the question badly. So I apologize if this is duplicate.
I'm on Intellij 2016.3.3
Go to preference, select Editor > Code Style > Javascript and choose Spaces, check the checkboxes in Within section "ES6 import/export brances", and if you want spaces in object literal braces, check "Object literal braces" and as well.
Go to settings and search for ES6 import/export braces. It should take you to Editor -> Code Style -> Javascript (or TypeScript). Just hit that checkbox on the spaces tab and it should add the spaces back.
As you are using Angular, I believe you need to edit the settings for the Typescript and NOT for JavaScript. As I am using IntelliJ IDEA 2021, I will give you the fix for the same. You can do so by going through the following path:
Go to File > Settings... > Editor > Code Style > Typescript
Click on the Spaces tab.
In the Within collapsible, tick the checkbox that says "ES6 import/export braces".
Click on Apply button and then click on Ok button.
If you now go to the Typescript file and hit the combo: Ctrl + Alt + L, it should now format the file correctly.
CAVEAT:
You have to be careful to ensure that you are making the changes for the Scheme that is applicable for your project. For example, maybe you have customized your Editor in some way previously and saved your customizations under a new name, such as MyCustomSettings. Once you do this, you will notice that there is an additional Scheme called the Default scheme. But MyCustomSettings will be your Scheme for your project and you have to make sure that you make the changes for the MyCustomSettings Scheme and not for the Default scheme. You can refer to the Schemes via the following path:
File > Settings... > Editor > Code Style > Typescript, there is a dropdown referred as Scheme. Choose the appropriate one for your Project and make sure you make the above edits in that Scheme.
I want to indent with tabs, so I checked "Use tab character" in settings. But when I open projects which were indented with tabs, IntelliJ IDEA still asks me if I want to convert the indenting to spaces or keep it that way. Also, it creates new classes with space indenting. How can I solve this?
Your screenshot shows the settings for your Default (1) scheme. Those settings are not applied to your project automatically. It's not enough to just select it in the combobox. You need to import this scheme into your project.
Click Manage... and Copy to Project, and it should work as expected. This needs to be done for all your projects.
Also, make sure you're changing the language-spefic settings, so instead Code Style select Code Style > Java (or whatever language you are using). Those settings may override the default code styles.
I could not find the live templates for Java! Who can tell me how to set? Thanks.
They're inside all the nodes that are not specific to another language than Java: iterations, output, plain, surround, etc.
As JB Nizet wrote there is not a special node for Java (but you can create one). If you want your own Live Template for Java created do the following.
Open Settings window (File -> Settings)
Click on Editor -> Live Templates
Choose Template Group in which you want to add your Live Template
(you can create your own Template Group if you wish)
Click on + icon and choose Live Template
Specify the Abbreviation, Description and Template text.
Do not forget to define the context (in your case Java)
Example
Here is an example of how to create your own TODO text
Open the Setting window with Live Templates editor (as specified above).
Click on + icon and select Template Group.
Name this group Java.
Click on + icon again and select Live Template.
Specify your Live Template and DEFINE CONTEXT.
In my case writing mtodo and pressing enter will result in:
// TODO myName
You can even use variables. Write in your Template text e.g. $DATE$ and $TIME$
// TODO myName $DATE$ $TIME$
Click on Edit variables button and assign to each variable (defined by dollar sign) and expression (predefined function).
Now mtodo will result in
// TODO myName 13.10.2015 15:39
Predefined functions could be found here. The example was created using IntelliJ IDEA 15 EAP.
For those of you who have taken Postfix completion for Live templates, it is worth mentioning they are different. from not-choosing pretty good answers from #JB Niznet and #vitfo, I guess that's the case for OP writer. The document, here, says:
Postfix code completion is similar to live templates, it transforms the current expression without selecting it. For example, you can type .if after an expression to invoke the corresponding postfix completion and wrap the expression with an if statement.
You can check out a list of postfix completions:
Open the Preferences window
Click on Editor -> General -> Postfix completion
By default, there is no JAVA group in this setting page.
However, these default settings distribute on each feature group. For example, iterations:
IntelliJ IDEA 2019.2.4 (Ultimate Edition)
How can i automate breaking lines (word wrap) in PHPStorm 2.1?
Automatic wrap example aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :
This expression has automatic wrap, because I did not press return.
As I understand you want Soft Wraps, when long line is wrapped on screen into multiple lines, but still remains as single line in file.
Soft Wraps
on per file basis
View | Active Editor | Use Soft Wraps
for all files by default
Settings/Preferences | Editor | General | Use soft wraps in editor
Right margin setting
There is also
Settings/Preferences | Editor | Code Style | General --> Wrap when typing reaches right margin
But that's different (it will make actual new line).
UPDATE: In current builds IDE can use separate value for right margin per different "language" -- as long as that language has an entry in Code Style settings.
Also keep in mind that any settings from .editorconfig files (if you have such files in your project and EditorConfig plugin is installed & enabled) will override the same from Code Style settings -- it's the nature of the plugin and not a bug (it meant to work this way).
Using EditorConfig support you can configure certain settings that otherwise may not be possible to do via Code Style (e.g. settings for languages/file types that have no separate Code Style entry).
Open Settings
Type "Use Soft Wraps" in search box
In keymap tab right click on "Use Soft Wraps" and add a custom shortcut
You will be able to toggle them with that shortcut
In PhpStorm 2019.1.3 You should add file type you want to make soft wrapping on it
go to Settings -> Editor -> General -> Soft-wrap files then add any types you want
For wrapping text/code line by deafault:
File -> Settings -> Editor -> General -> section "Soft Wraps" -> checkbox "Use soft wraps in editor"
In Webstorm 2020.3 i did not found any option for all files by default, but just change the pattern:
for ALL files:
Settings > Editor > General > Soft Warps >
Soft-wrap theses files: you can change value to:
*.*
(in the other words "ANY file name" and "ANY extension file")
for SOME FILES:
*.php; *.html
(Any files with exntension .php OR .html)
simple:
cmd+F8
You can find the list of shortcut by PhpStorm in menu Help -> Default Keymap Reference!
in phpstorm 2016:
Settings/Preferences | Editor | Code Style | General --> default option-> uncheck wrap on typing
To make it automatic
After applying this point:
Use Ctrl + Alt + S to open the settings menu
Select and click Editor
Choose Code Style
Change the default value of the Hard wrap value to 90
Go back to CodeStyle and choose any of the language you work with to make specific changes
5.1 I choose HTML and Select Other and i change the value of Hard wrap at 90 and wrap on typing to Yes
5.2 I choose JavaScript and Select Wrapping and Braces and change the Hard wrap at value to 90 and wrap on typing to Yes
Continue to do it with all other languages you work with
NB: other languages may be at a default values, change it if is not preferable to you
Apply and Ok to save the changes
Using phpstorm 2019.3.4 as well as new and older version :
Use Ctrl + Alt + S to open the settings menu
Select and click Editor
Choose Code Style
Change the default value of the Hard wrap value to 90
Apply and save changes
Press Ctrl + A to highlight and select all your codes in the text editor
Press Ctrl + Alt + L to format your code nicely
Or when using the default settings for Hard wrap at 180 , follow 6 and 7