Sublime Forum

Setting file type for a particular file, for automatic colouring and commenting

#1

Sublime Text knows to use // for comments in files with the extension .js and # for files with the extension .sh. But I have many files (such as /etc/hosts) which require a particular comment character, but have no extension that Sublime Text can recognize.

Is there a way, on a per-file basis, to tell Sublime Text “This is a file of type X; when I press Ctrl-/, please comment the selected lines in this file with the comment string Y”?

0 Likes

#2

This behavior does only work for files, which have a syntax highlighting und is usually provided together with the syntax definition (e.g. see here). Since the config files don’t have a syntax definition this command also does not work.
However one could create a new command on the same hotkey, which is only triggered on certain files and has the same behavior.

0 Likes

#3

it looks like https://packagecontrol.io/packages/Hosts defines which comment character to use for /etc/hosts, maybe install that package - even though the file has no extension, it should be detected based on it’s name

2 Likes

#4

This still only adds syntax highlighting and the behavior for hosts files, but not for other config files.

0 Likes

#5

For other config files I use the package https://packagecontrol.io/packages/Generic%20Config

@blackslate, you can also see the issue:

  1. https://github.com/SublimeTextIssues/Core/issues/1851 Apply the syntax to unamed file types as .gitmodules on sublime-syntax
0 Likes