Change file association manually
已回答
I need to change manually a file type for my file "script" (no file extension), from plaintext to other type (Ruby, if you ask).
In previous versions of Idea, it was just a one-click no-brainer... In Idea 11, I've spent like 2 hours trying to find a f...ing action button and reading TFM to no avail... There is NO such action anywhere in the IDE. OK, this is just ridiculous. HOW can such a SIMPLE action become so ridiculously complicated?! Where the f... is this f...ing thing?!
请先登录再写评论。
Settings > File Types
Nope, does not help - I do NOT want to register a whole new wildcard pattern. All I want is to change file association of THIS ONE single file. And guess what, Idea 11 simpy made it impossible, but WHY?!
Hello Ar.
I've switched to IDEA a few months ago (from Eclipse). An I can say I love it.
Back to topic, unfortunately I don't know how you can do that in IDEA 11.
But I am just currious how did you managed to do that in previous versions? and what versions are those?
Thank you in advance.
In previous versions, when you double-click a file with no known association (like file with no extension), Idea asked you how you want to open this file, and remembered this preference. In 11 version, for unknown reason, developers just decided that all files with no known association will be just treated as plaintext without asking the user. Which is just plain dumb stupid and makes no sense, compared to a pre-11 behavior.
This still works form me (Idea11): I get a popup and can choose how to edit/treat that file.
After that I can choose to deal with it as a text or switch back to whatever edit mode.
So, check your File Type settings...
/m
Well, all my files with no extension are shown as plaintext everywhere in Idea 11. Even if I clean all wildcards for 'text' in Settings>File Types, it does not help a bit, unfortunately. I have to manually enter every script file wildcard into Settings>File Types, which is so annoying.
I've tried this with Idea Ultimate Edition 11.01 and a pop-up was displayed allowing me to open the extension-less file with whatever editor I like.
Steps:
1. I've create a file named FileWithoutExtention
2. Open that file. A popup allow me to choose an editor. I did choose Groovy.
3. Open Settings and go to FileTypes, and select Groovy Files. I've noticed that a new entry (FileWithoutExtention) was added to default register patterns.
Maybe it's a bug, and in that case it is better to file it at http://youtrack.jetbrains.net/dashboard#newissue=yes
First of all, the reason this was changed is because previous versions of IDEA treated all files as binary, which means, for example, that the search for text didn't look into those files at all. Which is much more confusing than the current behavior.
Second, nothing has been made impossible. If you manually define the association in Settings | File Types, it will be recognized as the file type you've specified.
Third, the "Associate with file type" action should be available in the context menu for such files, but currently is not. I've filed an issue for that: http://youtrack.jetbrains.net/issue/IDEA-79574
Fourth, does your file have a hashbang line? There is support for auto-detecting a more specific file type by hashbang line, although it's not yet implemented for all languages.
Fifth, the original poster could have asked his question without all the alluded to profanity ("F...ing").
Sixth, the original poster's subsequent replies could have been made without the pejoratives ("dumb stupid") directed at the JetBrains developers.
Seventh, the original poster should learn that while Dmitry was kind enough to overlook the rudeness of items 5 and 6, typically one attracts more flies with honey then with vinegar and that common courtesy & manners are important.
My main point of frustration is broken workflow. Imagine, you are churning out dosens of small scripts daily, and a common one-click action to associate scripts file type suddenly becomes a detour into Settings complete with typing in patterns like "my_deployment_script_that_does_this_but_not_that". You get the picture, productivity loss is stupendous - thus my frustration.
Yes, either "Associate with file type" context action or hashbang-based autodetection would resolve this (there are not too many shebang variations out there, so it may be the best solution). Treating executable files as unknown binary by default may be another approach.
Lance, I'm extremely grateful that you were kind enough to share with us your valuable opinion on writing mannierism. Even though others may feel that unlike other posts, yours hardly contributed anything of substance to this discussion other than an illustration of an old English idiom "http://www.usingenglish.com/reference/idioms/every+ass+likes+to+hear+himself+bray.html".
Personally, I find that honestly sharing your frustration with developers can promptly attract their attention in a way that no amount of http://www.usingenglish.com/reference/idioms/brown+nose.html -ing is able to do. Long-term, it is also better for the developers since it is just so easy to slide into self-congratulatory complacency if you do not feel the pain inflicted upon your users by your very own design decisions. Which may well lead to loss of revenue and ultimately to downsizing that no amount of flattery will compensate for.
You, Sir, may most definitely disagree with my approach, as reasonable people do. Such disagreement does not necessarily call for imposing your specific sensibilities and stylistic preferences onto others though.
So what language are your scripts written in? We'd like to know where to put the hashbang detection first. :)
'#!/usr/bin/env ruby' is the only hashbang that is worthy of auto-detection, as far as I'm concerned. ;) Other esteemed gentlemen may disagree, though...
Under Settings -> Editor -> File Types you can define file type patterns.
Since no one here really wants to answer the question, I figured it out. If you have created a file without an extension (like an executable) and for one reason or another Intellij has decided not to give you the "Associate File Type" option on right click, you can do the following to fix it.
Right click > Refactor > Copy > Give the new file the extension you need (foo.sh) > Delete the original (foo) > Right Click > Refactor > Rename > Remove the extension > Hit Ok > You will then be given the file type association dialogue.
My opinion is that the "Associate File Type" option on right click should just always be present, even on known types.
Hope that helps someone!
Open preferences (ctrl + alt + s)
search File Types
enter the extension that you need to change.
Click '-' (remove symbol). as simple as that!
Thanks to this guy:
http://stackoverflow.com/questions/21336963/wrong-file-association-for-one-file-in-intellij-android-studio
Hope this helps!!
I have found in phpstorm that I can use the Refactor > Rename... function to associate a file of unspecified file type (e.g. a name with no extension) with a file type.
For example if I have a bash script named do_the_things I can Refactor > Rename it to do_the_things.sh which causes it to pick up the bash highlighting, then when I Refactor > Rename it back to do_the_things it keeps the bash highlighting.
Dan Revel solution (using Refactor to temporarily rename the file) doesn't work for me (I'm in PyCharm Professional 2016.3). When renaming it back the syntax highlighting is lost.
I would also like an option in a file context menu to manually associate THAT file (and not all other files with same extension) to a particular language.
Now, I have some nginx configuration files that are named 'production.conf', 'preproduction.conf' and so on... And I can't and I don't want to rename them for many reasons. I just want to be able to say "this is an nginx config file" and go on with my work.
I find this is a point of frustration.
Refactoring doesn't work if filetype is registered in that filetype dialog. In my case I accidentally associated one Vue.js file as React.js file. Figured out that this specific file was actually listed in filetype dialog and there under javascript. It had entry for one other file for mine as well so deleted both and then file was recognized correctly.
So just to clarify two files of mine were listed below that highlighted *.js
Yep, dumbest thing ever. If you associate a file with a file type you can't change it. I tried renaming the file, I tried deleting and creating it again, I even tried editing the workspace xml to remove any mention of my file. This thing is as stubborn as a mule.
5 years later and still the same ergonomic issues.
Once a file has been associated with a file type, the "Associate with File Type" context menu is no longer available (why?), and the only way to change the association is to dig through all the registered patterns under "Preferences... | Editor > File Types". The shebang detection does not work (at all), and bash files are regularly registered as "Text Files".
Can someone explain why I don't see File Types in my settings?
You're in default settings. Go to Settings instead.
@DanRevel's answer helped. This is exactly what I did (in Intellij 1.4):
1) Right-click on the file that you want to change the file association of.
2) Click Refactor -> Rename
3) Change the file extension of the name and click Refactor
4) Select a file association so that Intellij automatically opens the file in the format you want.
5) Repeat these steps for the same file and rename the file extension to the original name.
Sometimes it's just easier to `rm -rf .idea` and re import project instead of browsing through file associations.
This is crazy that this is still an issue after 6 YEARS. I've tried deleting the file and re-creating, still a text file. Renamed the extension, can change to another one without a problem, .js for exmaple. Flip it back to a .php extension, and it treats it as a text file again. Delete the .idea folder, re-import the project, same deal. What stores the association of each individual file with it's file type??
See http://stackoverflow.com/a/13374653/104891.
@Serge Baranov - yes! It had added that single file in there, removed that file as being text file type association and life is good again. Thanks for the quick reply!
Please make it easier to dynamically override associations-by-extention, that's so 90s. We need to work with all kinds of little conf files and whatnot. Don't make us clutch on to emacs and vim! :-) Thanks for a great set of IDEs btw, loving CLion.
Atom / VScode / VIM could do this much easier
CTRL+SHIFT+L , Type the language u want, select it
CTRL+K, Then press M
Just Type:
set syntax=`the language you want`
Sorry,we are in the 90s. ............just a joke...........