Get Visual Studio Code to syntax highlight extensionless files as bash scripts?

As a workaround you can manually set highlighting for your file by clicking on the bottom right corner of VS code editor "Select language mode" and then select the file type (also Ctrl+K M).

The down side is that you have to do this every time but it is a lot easier than the renaming procedure you described.

enter image description here


if there is a way to make Visual Studio Code even smarter, like looking at the first line for #!/bin/sh then that would be even better.

VSCode actually already does assoicate files with shellscript based on the shebang. However, note that it doesn't detect it dynamically - if you add a shebang, you will need to close and reopen the file for VSCode to notice it.


You can use globbing to hack it into your settings.json as found in this post.

    "files.associations": {
        /* BEGIN: hack to make files with no extension use bash syntax highlighting */
        "[!.]": "shellscript",
        "[!.][!.]": "shellscript",
        "[!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript",
        "[!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.][!.]": "shellscript"
        /* END: hack to make files with no extension use bash syntax highlighting */
    },