IntelliJ auto detect indentation for each file - intellij-idea

I recently switched from Sublime Text to IntelliJ and I trying to figure out, if there's a way for IntelliJ to auto detect what indentation the current file is using and use that instead of the default
I have to deal with a lot of 3rd party code, which can have different indentation settings, which I'm not allowed to change for obvious reasons.
Sublime Text was able to detect and abide to the indentation for the current file, which is quite intuitive and unobtrusive. IntelliJ on the other hand just sticks to it's own settings, resulting in mixed tabs and spaces, wrong indentation levels and wrong merge conflicts.
Is there a way to make IntelliJ behave, other than having to manually change the indentation settings every time I get a file with different indentation.
Thanks

In recent versions of Intellij there is a Detect and use existing file indents for editing setting for this:

Each project you open in IntelliJ has it's own settings. You will need to set the indent style the first time you open up the project, but it will be saved after that (and can be different for every project you work on). From the IntelliJ help site:
Project settings are stored with each specific project as a set of xml files
under the .idea folder. If you specify the
default project settings,
these settings will be automatically used for each newly created project.
You can edit the indent settings for the project in the Code Style dialog.

Related

File named "auth_actions.dart" won't be highlighted in Intellij-idea

I created a file named "auth_actions.dart" in a dart project(either angular or not). The file content would have text colour being plain white, without any highlighted.
If I rename it to "auth_action.dart" or "auth_actionss.dart", the highlight will come back.
I did some experiments even from some random projects downloaded from github, all of them had this issue.
Anyone know how to fix it? Does anyone see the same issue using the name "auth_actions.dart"?
I assume you accidentally added the file to
Preferences > Editor > File Types > Recognized File Types > Text
Remove it from Registered Patterns to get hightlighting again.
You could accidentally mark it as plain text (the option is in the right-click menu). In this case, the option to mark it back as a Dart file is also in the context menu.

File-based, not Folder-based, Projects in Atom?

I'm trying to switch to Atom as my programming editor so that I can gain handy features like linting for Perl, JavaScript, etc. However, over the last two decades, I've used a string of editors (UltraEdit, jEdit, BBEdit) that allowed me to add individual files from different folders into projects. My main coding project actually spans several remote SFTP servers and the "folders" in my BBEdit project do not necessarily correspond to any file structure on disk.
I cannot seem to figure out how to set up a project in this manner in Atom (or similar editors such as Brackets). Is there a way to configure Atom and its extensions to produce a result similar to an UltraEdit/jEdit/BBEdit/Komodo project? I thought about creating a new project directory and symlinking to the real files, but that seems like a hack at best.
I belive its File > Open Project or something like that. I personally like Sublime Text 3 but Atom and Sublime are the same.
The best solution I have found so far would be to install opened-files package. By default it persists all files you have opened (even after you close them) until you close atom editor. I don't think it would work well for bigger projects as it lists all the files under one tab in tree view.
If you want to persist open files you might want to use project-manager package. To keep files listed under 'Opened files' tab after you close them (and atom), you need to press bookmark icon next to tab name. Once you add the project it auto-saves file structure when you close atom. To add project to project-manager write project-manager save in command palette. To list all projects from project manager press shift-alt-P.

In IntelliJ IDEA, how can I reset the per file indentation decision?

IntelliJ IDEA shows a small notice at the top of a file when the detected indentation inside the file does not match that configured in the settings dialog. It also allows to switch the indentation to the configured setting, which is a useful thing.
But now I have two files for which I would like to revert that decision and not apply my locally defined indentation. However this appears to be impossible...
Even changing the configured indentation setting does not have an effect on those files I once made that decision for. It appears that the decision is set and stored as a per file configuration.
Question: is there any way to remove that per file setting again?
Have you tried Edit -> Convert Indents -> To Spaces / To Tabs ?
This should be file specific.

Use IntelliJ code style in Checkstyle

Essentially, I want to export the code style settings from IntelliJ (the default one is fine) and use them in Checkstyle. (It's for a maven build validation kind of thing that is already setup, but we want to use IntelliJ's code style, not Sun's or Googles)
Step one should be to export the IntelliJ code style. Easier said than done, it seems.
Now, I know there is a lot of material on this on both SO and other places, but I simply cannot find the code style xml file anywhere, not even after using "copy to project" or "save as..." in the IntelliJ settings code style dialog.
I also tried exporting code style through the IntelliJ File menu, but it will only export the code style from areas that have changed (eg. change tab space from 4 to 2 and it will only export the "OTHER_INDENT_OPTIONS" part of the code style).
I should add that I'm using IDEA 14.1.4.
Is it possible to export the complete IntelliJ code style?
Unfortunately it is not possible to do what you want for (at least) three reasons, the first two of which you have already raised:
While is possible to export a code style file from Intellij IDEA using File->Settings->Code Style->Java->{Click the Settings icon}->Select Export... from the popup menu, that exported XML file only contains the changes you have made from the default settings.
Those exported settings are in a format that is only meaningful to Intellij, so even if you could export every single Java code style setting to an XML file, you would then have to massively edit that file to make it meaningful to CheckStyle.
Finally, note that there is an open request for Intellij to do exactly what you want. See IDEA-149529:
Current export functionality for Code Styles is lacking. Only useful
for other users of IntelliJ or as a backup. Only exports the diff
between user defined settings and the built-in default. This makes it
very difficult to produce a matching style for other
formatting/beautification tools.
It would be helpful if the export had the option of exports ALL the
settings IDEA uses.
However, there is an alternative approach. Instead of providing an Intellij IDEA file to Checkstyle, provide a Checkstyle file to Intellij IDEA...
Install the Checkstyle plugin, and then open two sets of one or more duplicated files in Intellij IDEA, one set configured to use IDEA's formatting and one set configured to Checkstyle's formatting.
Repeatedly tweak the Checkstyle settings until its opened file(s) are formatted to conform to the corresponding files formatted by IDEA. When the sets of files match create a Checkstyle XML rules file. Tedious, but only a one time activity.
Finally, you can then import your customized CheckStyle XML rules file into Intellij Idea, using Import Scheme -> CheckStyle Configuration as as shown in the screen shot below (if, and only if, you have installed the CheckStyle-IDEA plugin). This functionality did not exist when the OP was created. For more details see the following bug report: IDEA-61520 Codestyle from Checkstyle and in particular the response from JetBrains dated 2/8/16.
See also:
Intellij IDEA bug Configure code style from checkstyle #126
SO post IntelliJ IDEA code format from checkstyle configuration
I was looking for an answer to this too. I suppose you want to add it to your build process like I do. Since I saw no value in enforcing something that can't be automated, I settled on (haven't implemented yet) executing the style formatter as a pre-commit hook (I use git) https://www.jetbrains.com/help/idea/command-line-formatter.html against all files in the changelist. I use the defaults too, and this would be enough.
Since I don't have any customizations, I would not know if an exported code style xml would run the default in addition to the diff in the xml. Either way, there's no point in enforcing code style rules that can't be automated.

Intellij Idea how can I specify colors for a specific file type?

I am using a color theme that I am perfectly happy with, but I am dealing with a lot of ".impex" files that are unique to the Hybris platform. The IDE essentially sees them as text files. How can I add syntax coloring to these ".impex" files so the text is not just all one color?
Maybe this plugin can help you.
Syntax highlight for impex files
Besides, you can register a file pattern to a recognised file type: Preferences -> IDE Settings -> File Types.