6

I want to associate all files without extension to xml format in VSCode.

When I do below, it makes all files (even with extensions) as xml. "files.associations": { "*": "xml" }

Any way to achieve this?

Abhishek Agrawal
  • 2,183
  • 1
  • 17
  • 24

1 Answers1

7

This solution does not work for the latest versions.

"files.associations": {
    "[!.]*": "xml",
},

For the latest versions, you need to add a rule for each file length.

The example shows a solution for files up to 30 characters long.

Far from the best solution, but no better solution has yet been found.

"files.associations": {
    "[!.]": "xml",
    "[!.][!.]": "xml",
    "[!.][!.][!.]": "xml",
    "[!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
    "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "xml",
}
Victor S.
  • 2,510
  • 3
  • 22
  • 35
  • This worked for me for c++ Linux include files, e.g. when opening ``; though, note that it only worked when I did `"cpp"`, the exact right Language Mode string, rather than `"c++"`, which did not work. Thanks. – Andrew May 30 '21 at 04:43
  • Update: Actually, this seems to be causing **all** files to open in whatever Language Mode... :/ – Andrew May 31 '21 at 10:28
  • from your comments, I did not understand what needs to be done or what is not working as it should – Victor S. May 31 '21 at 17:31
  • This answer's approach will cause literally all files that are opened to open in the specified Language Mode that was specified, i.e. `"xml"` or `"cpp"`, whatever was specified here. – Andrew Jun 02 '21 at 11:48
  • all files without extension (no dot in full name) will open as 'xml' files. – Victor S. Jun 02 '21 at 14:08
  • Along with all other files. I'm telling you what happens. – Andrew Jun 03 '21 at 15:53
  • I have no problems. Can you give an example of such a file that opens with the wrong extension and vscode settings? – Victor S. Jun 04 '21 at 08:11
  • No because I'm not a 4 year old. – Andrew Jun 04 '21 at 11:55
  • I don't care about age. Everything works for me as it should. I can't reproduce your problem. Check it on vscode without settings. – Victor S. Jun 04 '21 at 12:49
  • This does not work for me either. Any file is opened as the association. In fact it changes the settings.json association when I save the setting. – Mark Jul 19 '21 at 21:22