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

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.

Related

Can Intellij open files for editing at the top/start, not the last edit position

If you open a big java file, scroll to 'somewhere' and make a change. Then close the file and re-open it, Intellij will open it at the last point that you made the change. This is annoying, can it be changed so it always opens the file at the top like most file reading applications do
I don't really remember seeing such an option, but you can work around with some small tricks.
1) include line number of the file, eg to open MyUI at line 10: CTRL + N & type myui:10
2) navigate to symbol, et to navigate to method init of MyUI: CTRL + SHIFT + ALT + N & type myui.init
This same misfeature annoyed me to the point of doing something about it, as I prefer to open files by double-clicking them in the Project tree (which doesn't present the option of typing in a line number). Also, it bothers me to be typing in line numbers on every single file option simply to get the text editor to not jump to wherever I was editing six months ago.
Sadly, there's still no option to toggle this behavior. (JetBrains really, really doesn't like it when users prefer simpler behavior than their flagship defaults.) But it's very easy to strip the "last edited position" history out of the saved workspace.
Optional first step: If you have more than one workspace, you need to find its configuration file. Wherever you designated the project root location should contain a .idea subdirectory with a workspace.xml file, for example $HOME/IdeaProjects/MyProjectName/.idea/workspace.xml. There will be a ProjectId key and some "nonsense looking" value, for example
<component name="ProjectId" id="wZadhKS8vnOD4GBBT2Pz93rDw" />
You'll need that unique ID.
Actual steps:
Exit IDEA. You can't do this while the IDE is running.
Go to your personal IDEA directory. This can vary based on version; for me it is currently %HOME%/.IdeaIC2019.3. It will have a config/workspace subdirectory containing an XML file for each of your workspaces, named after the ProjectId above. For example,
$HOME/.IdeaIC2019.3/config/workspace/wZadhKS8vnOD4GBBT2Pz93rDw.xml
For 2020.1 and later, this location has moved; for me the default is now %APPDATA%/JetBrains/IdeaIC2020.1 and there is no config subdirectory, so: C:/Users/me/AppData/Roaming/JetBrains/IdeaIC20201./workspace instead.
That XML file contains the saved last-edit positions in a node like this:
<component name="editorHistoryManager">
this is all the stuff that causes annoyances
</component>
Make a backup copy of the wZa...3rDw.xml file, whatever it's called for you.
Use your favorite programmatic XML editor tool to remove that node. For example:
xmlstarlet ed --omit-decl -d '//component[#name="editorHistoryManager"]' wZa...3rDw.xml > tmp
mv tmp wZa...3rDw.xml
The next time IDEA is launched, all files will open at their beginning, the way God and nature intended.
For bonus points, automate the above in a script that runs behind the scenes as appropriate. :-)
IDEA does something a little unusual with its XML involving whitespace, and tools like XMLStarlet often do something else. As XML is whitespace agnostic this makes no difference at runtime, but it does mean that if you want to compare for correctness or you're keeping the IDEA configuration in revision control, there will be a lot of extraneous "churn" in the diffs. If this causes too much noise, you can augment step (4) to something like
xmlstarlet .... | sed -e 's#"/>$#" />#' > tmp
to insert extra whitespace back, in most of the places where IDEA had originally put some. (I didn't test this heavily, as the lack of whitespace isn't important to me or to the IDEA runtime. It would have been nice to have a cleaner diff, but whatever.)
Caveats: As IDEA can save its config in either a directory-based layout, or in a all-in-one-file layout, the steps to find the workspace config file may vary wildly. What I wrote above works for the default directory-based layout.

Sublime tab size only working for some files

Im using Sublime Text 3 for a javascript app. When I tab, I want it converted to 4 sapces. So I have set:
"tab_size": 4,
"translate_tabs_to_spaces": true,
This works fine. But weirdly, on some files (that also have .js extension like the ones it works on), a tab still only translates to 2 spaces. How can i fix this?
In my case, I had to set "detect_indentation": false, and then close and reopen the file. When you leave the file opened, it will "remember" the indentation even across Sublime restarts.
All settings in Sublime Text follow an Order of Precedence. Here's an hypothetical example for JavaScript (in ascending order):
Packages/Default/Preferences.sublime-settings
Packages/Default/Preferences (Windows).sublime-settings
Packages/User/Preferences.sublime-settings
Packages/JavaScript/JavaScript.sublime-settings
Packages/User/JavaScript.sublime-settings
In this case, the bold settings will override all the others. In your case, a JavaScript package might override your user preferences.
What you can do is define tab_size in Preferences > Settings - Syntax Specific. Make sure you're current view is a JavaScript file before opening the setting.

Can I make IntelliJ IDEAs auto indent ignore previous lines?

Auto-indenting in IntelliJ IDEA seems to automatically takes lines previous to the selection in to consideration. This means that if the indentation is incorrect in the part of the file you're working on (e.g., 3 or 5 spaces where there should be 4, or even worse, a mix of tabs and spaces) it's annoyingly difficult to add correctly indented code.
Both new lines I'm adding and lines I use auto-indent on because I've changed them anyway get messed up like this. Since the file I'm working on is being worked on by someone else as well on another branch, I really don't want to modify over a third of the file just to indent everything correctly, but I would still like the lines that I'm actually modifying/adding to be correct - I don't see any reason to perpetuate the error when it's not necessary.
Currently the best mechanism for fixing it I've found is to manually do the spaces on a line and go from there, but it's really quite annoying, especially since I can't use the tab key or IntelliJ will immediately move to the incorrect indentation. It's barely better than copy/pasting the text to Sublime Text, fix the indentation there and paste it back without formatting.
My apologies if this has already been asked, I've tried to search for it, but it's very hard to search for this as there's so many auto-indent questions.
IntelliJ IDEA recently added a feature (in v14 or 1v4.1 if I recall) where it will detect indentation that is different from your settings. It will honor those indentations (in order to keep the file consistent). Usually as soon as you start editing the file, you get a banner, although that can be turned off. The banner looks like this:
This allows you to modify this setting on a per file basis, or turn it off completely (i.e. the "Show Settings" option).
I suspect this feature is what is causing you the issue. I am not sure how it handles a case where a file has mixed indentation (e.g. most of the file is 4, but some sections are 3 or 5 spaces). You can try turning this feature off in Settings > Editor > Code Style > "Detect and use existing file indents for editing"

Unable to change some files in RubyMine project

Currently I'm having an issue where I cannot make any changes to some files in my project. When hitting the return or space bar key it will only select text and not create new lines or spaces respectively.
I'm fairly certain it has something to do with the VCS features but cannot seem to find any settings to correct the Read-Only issue I'm running into.
This issue did raise it head after installing the Dash plugin. Not sure if this is coincidental or related.
Thanks!
update: After further test it looks like some files go into a sort of preview mode. Return and Space bar keys will let you scan the file and hitting any other keys will wake up the edit function. Strange?
IdealVim caused this for me. Definitely plugin related.

IntelliJ auto detect indentation for each file

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.