Sublime Forum

Remember syntax selection for file w/o extension?

#1

Is there a way for sublime 3 to either remember syntax style choice for files that doesn’t have any extension? I know there is a default option but that doesn’t cut it.

I guess a way this can work is to use a hidden/.dot in the dictionary to remember the choice of file type or have ST ask for filetype each time a generic file without extension is open (but I’d image that a little bit annoying, but as least it can be an option?)

0 Likes

#2

I don’t know of such a plugin to remember individual files’ syntax choices, but I suggest adding this to your key bindings:

  { "keys": ["ctrl+alt+s"], "command": "show_overlay",
    "args": {"overlay": "command_palette", "text": "Set Syntax: "} },
2 Likes

#4

IF the file you are editing has a fixed name, a predictable file name pattern or a fixed shebang, or file content, then you can use the ApplySyntax plugin:

  1. Cmd/Ctrl+Shift+P > Package Control: Install Package > type ApplySyntax > Enter
  2. Cmd/Ctrl+Shift+P > type ApplySyntax > pick ApplySyntax:Settings

You’ll see in the default config in the left panel that for example .profile files are treated as "ShellScript/Bash".

For fuzzy matching have a look at the predefined globmatch rules, for example the ootb rule for bash:

{
    "syntax": [
        "ShellScript/Bash",
        "ShellScript/Shell-Unix-Generic"
    ],
    "extensions": ["bash", "sh", "zsh", "bashrc", "ash", ".profile"],
    "rules": [
        {
            "globmatch": [
                "**/.bash*",
                "**/.z@(shrc|shenv|profile|login|logout)*"
            ]
        },
        {"interpreter": "bash"},
        {"interpreter": "zsh"}
    ]
}

I needed this for my ~/.aliases file, so one option is to add a shebang in the first line in the #!/usr/bin/bash, while another option is keeping the file as is without a shebang and in the ApplySyntax user config override the default extensions for bash with:

"extensions": ["bash", "sh", "zsh", "bashrc", "ash", ".profile", ".aliases"],

ps. I have no affiliation with the plugin developer

0 Likes