Sublime Forum

Toggle comments not working

#1

I’m running Sublime 3, build 3143 on Ubuntu 17.10. Comment toggling is not working for me. I’ve tried using the default (Ctrl + /, Ctrl + Shift + /), and I’ve tried alternate keybindings as well. If I enable logging, I see that Sublime thinks that comments are being toggled on or off, but nothing is actually happening on my text document. Additionally, if I try to toggle comments via the menu, the same thing happens. That is, nothing at all in the document, but logging shows that comments are being toggled.

0 Likes

#2

If your syntax is not configured to use comments, they will not work. This is a example configuration for java:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Comments</string>
	<key>scope</key>
	<string>source.java</string>
	<key>settings</key>
	<dict>
		<key>shellVariables</key>
		<array>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_START</string>
				<key>value</key>
				<string>// </string>
			</dict>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_START_2</string>
				<key>value</key>
				<string>/*</string>
			</dict>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_END_2</string>
				<key>value</key>
				<string>*/</string>
			</dict>
		</array>
	</dict>
</dict>
</plist>

Which language are you using?

If the comments are configured, but still not working, it could be a bad package which you have installed is breaking things. Then you can try reverting Sublime Text to a clean state:

  1. https://www.sublimetext.com/docs/3/revert.html

You can see what Sublime Text is doing if you enable the console logging running these commands on the Sublime Text console, to enable and disable the debugging:

sublime.log_input(True); sublime.log_commands(True); sublime.log_result_regex(True)
sublime.log_input(False); sublime.log_commands(False); sublime.log_result_regex(False)

You can open the Sublime Text console by going on the menu View -> Show Console

0 Likes

#3

@addons_zz, that was the missing piece of info that I was looking for, thank you. ST didn’t know what to do with my .audit file. I renamed it to a .py and it toggling comments worked just fine.

Now, where would I go to add a custom syntax definition for a particular file extension?

0 Likes

#4

You language is not already available on https://packagecontrol.io?

You need to create a file like the example above, with the extension .tmPreferences, the file name should not matter. But usually they are named like Comments.tmPreferences. On it you should configure the comments characters type and the target language scopes.

You can give a look into:

  1. http://docs.sublimetext.info/en/latest/reference/comments.html
0 Likes

#5

@addons_zz, it’s an CIS benchmark audit file that’s… Well, I wouldn’t say it’s xml, but it’s at least “xml-like”. It uses standard # comments.

Thanks for the link!

0 Likes