Sublime Forum

Automatically detect syntax on save


When a file is saved and no syntax highlighter has been selected, it would be convenient to re-detect based on whether the file has a shebang or not. For example:

$ subl foo

Might have no syntax highlighting when the file is opened, but if it is saved with the contents e.g.

#!/usr/bin/env zsh
echo foo

We should auto-detect bash or whatever’s syntax highlighting.



hmm, I think this would be very inefficient, because changing the syntax for a source file is very rare. If the syntax is re-evaluated on every file safe it would do next to nothing.


#3 should work for you.

By default if the scope is text.plain, it re-detects the syntax if the user modifies the first line. So it should be bash immediately once you type #!/usr/bin/env zsh.

1 Like