In VS Code I usually open files that have no extension just filename
. I know I can change the language syntax with Change Language Mode --> Language that I want but I don't want to do this manually every time I open such a file. Can I make a default to this language every time I open a file with no extension?
I know I can do this:
"files.associations": {
"*.myphp": "php"
}
But what if there is no extension? Also I want to be able to do this without affecting the other file types (that have extension).
In VS Code, we default the language support for a file based on its filename extension. However at times you may wish to change language modes, to do this click on the language indicator - which is located on the right hand of the status bar. This will bring up the Command Palette for Select Language Mode.
You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X).
VS Code's globbing doesn't currently seem to have a way to detect files with no extension. Every time someone opens an issue, they point it back to this issue here. They detail their globbing support here.
That said, I do have a hacky solution to this. Put this in your "WORKSPACE SETTINGS" (not your general settings unless you really want this to be global).
{
"files.associations": {
"[!.]": "php",
"[!.][!.]": "php",
"[!.][!.][!.]": "php",
"[!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php",
"[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "php"
},
}
This works by adding a rule for every file name length and ensuring that the file cannot have a period in it (up to 20 characters in my example). This is a horrible hacky solution, but if you hold your nose and set it once, you can forget it and things just work. I do this in my dotfiles repo to associate extension-less files with "shellscript".
You an also do this just for a specific directory by using the double star glob: "**/just_this_dir_name/[!.]": "php"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With