How do I enforce LF line endings in Jetbrains Rider 2018.1 - intellij-idea

I'm frequently running into line ending issues with my JetBrains Rider 2018.1 installation under Windows 10. The IDE turns existing LF files into CRLF files once I edit them. I haven't yet found a way to configure it the way I want.
I would like to always only have LF in my files (for new ones and for edited ones). During a commit process, I don't want to get distracted by line ending changes.
My git is set to core.autocrlf=input. So it should behave neutral and use the as-is settings.
I know I can edit each file manually via the Line Ending switch button on the bottom right of the editor, but I feel that is quite cumbersome.

To change the default line ending for new files, Go to File → Editor → Settings → Code Style and in the "Line Separator" dropdown select "Unix and OS X (\n)".
To change the line endings of existing files, select the files in the "Project" view panel, then go to File → Line Separators → LF - Unix and OS X (\n). Make sure you don't break anything though - some file formats (eg .bat) only work with specific line endings.

Related

Choose editor depending not only on file extension

Is it possible to use a different editor in IntelliJ depending on file contents (or at least file name) instead of just file extension? IntelliJ Idea highlighting depending on file structure; NOT file extension says it isn't, but perhaps it has changed in last 6.5 years?

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.

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.

Webstorm not recognising JavaScript file

Webstorm doesn't recognize one of my .js files as a JavaScript file so I'm losing syntax highlighting and being able to add break points. I've looked in the workspace.xml file and the file in question seems to have similar settings to other .js files that work correctly.
If I change the name of the file it works ok. So somehow Webstorm is stuck on misinterpreting the type of a file that has this name. Where else can I edit the project?
So I see three possible reasons for the problem:
The file was marked as 'Plain text'
There is a pattern for 'Text files' file type that matches this file (or back: file type 'JavaScript' exclude this file name). See image below
There is a custom plugin that overrides default behavior for files with this name (unlikely)
Updated: after several years I've found one more reason for the behavior and most likely it the main source of the issues. When you create a file without any extensions the "Register New File Type Association" is appeared. And you can accidentally specify a new file type, for some file name. It is can be fixed with (2) but it is the reason why the pattern was added there.
Note: the solution works for all IDEA-based IDEs: IntelliJ IDEA, WebStorm, RubyMine, PyCharm, PhpStorm.
File -> Settings -> Editor -> FileTypes -> Text files -> check for "ContentRepository.js" pattern there and remove it.
If the file was marked as "Plain Text", then this can be fixed as follows:
Right click on the file.
One of the menu options is "Mark as Javascript" . Just below "Delete".
Click that. Your file is now recognized as javascript by WebStorm.
Since WebStorm was not allowing screenshots after right click so couldn't add it here.
My problem was with Auto-detect file type by context
For me this did the trick
1) Preferences
2) Editor
3) FileTypes
4) Search for javascript
5) Add *.js to registered patterns
You can also try "Template data languages" (in file > settings) which will force a specific language synatax high-lighting on a specific file or folder. See screenshot below
For a block of code you can also use "language injection". Simply high-light the block of code, wait for the little lamp to appear then select the bottom choice and then the language you need (screenshot also attached)
In case it is helpful elsewhere (OMG this was scary).
For some reason IntelliJ was not recognizing any .js file in my project (even after .idea removal (rm -rf .idea)).
I went to Webstorm (in my case RubyMine): Webstorm > Preferences ... > Editor > File Types then went to Recognized Filed Types, picked Javascript (but whatever file type you are missing will do), then added back a Registered Patterns entry of *.js
Of course, press Apply and then Ok.
Wow, scary stuff. but solved my problem, hope it does for someone else.
I was always trying to add .js as a recognised file types, but somehow .js was added to Ignored Files and Folders.
I just removed .js from Ignored Files and Folders and it worked for me.
Preferences
Editor
FileTypes
Ignored Files and Folders
Remove *.js
2022 update!
Right click on file and choose JavaScript

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.