Disable reformatting code when saving files - ide

I made a small change to an old java file in IntelliJ and when I save the file the IDE automatically reformats all the code. Normally this would be preferable, however it seems almost every line has unnecessary white space that gets cleaned up. Now it appears the entire file was modified even though I only made a small fix. This will make looking at the significant changes in VCS more difficult.
Is there a way to disable code reformatting when a file gets saved? So far I haven't had any luck finding the setting in the Project Settings dialog. I'm using IntelliJ IDEA 9.0.2
Alternatively I could perform the reformat, commit the changes, and then make my modification but I feel that this will end up happening a lot and I don't want to impose my formatting preferences on code owned by other groups.

Settings | Editor | General > Other | Strip trailing spaces on Save -> None.
Updated for IntelliJ Idea 2021+
Settings | Editor | General > On Save | Remove trailing spaces on: <...> -> None.

For newer versions (at least WebStorm 2018), Ctrl + S is bound to a save Macro that has a reformat code action followed by save.
You can remove this reformat with Ctrl + Shift + A search for Macro then modify the save one.
Edit | Macros | Edit Macros | save | - on the Action: Reformat...

You can add these comments to make it temporarily disable formatting on the file, or a specific function:
// #formatter:off
If you want one section to remain, you can also add this:
// #formatter:on
IntelliJ Documentation Link
If #formatter:off is not working, you can enable it in preferences:

Today in 2020 IDEA is silently formatting HTML before commit, which might break your web pages appearance. To disable that unselect this checkbox:

Preferences -> Tools -> Actions on save -> uncheck "Reformat Code"

Settings > Tools > Actions on save > first line with checkbox "Reformat code"
change "Whole file" to "Changed lines"
As it advertise only the modified lines will be affected by formatting on save.

Related

PhpStorm AutoComplete code is not working

I'm using PhpStorm over 3 months and it's a good IDE. I do not know what I've clicked yesterday but since yesterday I have issue with code completion in CSS mainly.
On the screen I have VS Code and PhpStorm and also I've opened the same project.
In VS Code it works perfectly. In PhpStorm it doesn't. I tried some Google First Aid like clear cache, update the IDE, turn On/Off Safe mode etc. but nothing changed.
My Code Completion settings:
Based on your PhpStorm editor area screenshot (many thanks for that BTW: not many people do post it even if asked), all your CSS files are treated as a Plain Text. It's rather unlikely to be a glitch, more like accidental settings change.
Settings/Preferences | Plugins -- make sure that CSS plugin is enabled. If not -- enable and restart the IDE.
If still the same: Settings/Preferences | Editor | File Types -- locate "Cascading style sheet" entry and make sure that it has *.css pattern there.
If not there -- it's possible that you have somehow reassigned it to "Text" file type. If it's there -- just add *.css to Cascading style sheet patterns (it will remove it from Text when doing that).
If still nothing: you would need to provide more/new screenshots.

PhpStorm is doing something with blank lines so that they are shown as changes in my commits

Basically after changing files in PhpStorm and commiting I get a lot of these blank line changes but I haven't touched any of them.
I turned on "keep indent on empty lines" and turned off "remove trailing spaces" but it didn't fix the problem.
What's going on here? For now I have to stage lines instead of whole files to avoid pushing garbage changes but that's less than ideal.
I turned on "keep indent on empty lines" and turned off "remove trailing spaces" but it didn't fix the problem.
Settings/Preferences | Editor | General | Remove trailing spaces on: is indeed the option that controls such behaviour. As per your description you already have that disabled.
If you have .editorconfig files in your project then corresponding setting from there (trim_trailing_whitespace) will overwrite corresponding IDE settings. It is expected as it's the whole nature of such files.
In this case you have a few options here:
either edit your .editorconfig file accordingly (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#trim_trailing_whitespace)
or disable such support in the IDE (Settings/Preferences | Editor | Code Style | Enable EditorConfig support)
or even more radical one: disable EditorConfig plugin completely (which affects the whole IDE: all projects / code styles).

Remove automated closing bracket comments in IntelliJ IDEA

I'm seeing following happen when working in intelliJ IDEA with Dart based project
All comments there i.e // AppBar are auto generated, I assume for easier tracking of what closing brackets belong where. Weird bit is that I can't even highlight them, nor delete them and when I copy code they are not copied over.
Is there a way to disable this feature in the ide?
The checkbox is in Settings (Preferences) | Editor | General | Appearance, toggle 'Show closing labels in Dart source code'.
And in the vs code editor, change this setting to false
"dart.closingLabels": true
You can find this setting easily. Go setting and search(Ctrl+f) dart.closingLabels
Update 24.11.2019:
If you want to customize the closing label color, you can do this. In vscode, open your settings.json file and set this setting
"workbench.colorCustomizations": {
"dart.closingLabels": "#FF5733"
},

How do I prevent PhpStorm from moving cursor to the left when I press Ctrl+S for save file? [duplicate]

I just updated to PhpStorm 2016 and I noticed that suddenly every time I press Ctrl + S to save the file it removes the spaces/tabs that I pressed to continue writing after testing this bit of code.
Pleas help, this is very annoying for me, since I save my file after every line of code.
Here is a screenshot when I'm about to save, so after hitting Ctrl + S the text cursor will move all the way to the left, deleting all spaces & tabs.
You need to disable Settings/Preferences | Editor | General | Remove trailing spaces on: option.
(NOTE: in older IDE versions you may have just a drop down box and have to select the None option there)
P.S. Please note that if you have .editorconfig files in your project then corresponding setting from there (trim_trailing_whitespace) will overwrite such IDE setting. It is expected as it's the whole nature of such files.
If you do not like that then either edit your .editorconfig file accordingly (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#current-universal-properties) or disable such support in the IDE (Settings/Preferences | Editor | Code Style | Enable EditorConfig support)
I recently experienced the behavior that trailing spaces got removed everywhere although the option Settings/Preferences > Editor > General > Strip trailing spaces on Save was set to Modified Lines. Setting the option to None didn't help nigher.
The reason for that was, that I had installed the JetBrains IDE plugin EditorConfig. In the root of my (PHP-) project I had a
.editorconfig file with the setting trim_trailing_whitespace = true. Setting that to false, fixed the issue.
PhpStorm 2021.2.3
Just Settings/Preferences > Editor > General
scroll down to On Save

Php Storm : How can i automate breaking lines in PHPStorm 2.1

How can i automate breaking lines (word wrap) in PHPStorm 2.1?
Automatic wrap example aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa‌aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa :
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