Sublime Forum

Comment Hotkey Doesnt work even after remapping

#1

Hi all. Had Sublime for a while. Saw that the comment function was not working. So paid the $99 to get the full version. This did not fix the problem. Went here and followed the directions to few ways to get the comment feature working but none fo them worked for me. What am I doing wrong??

OSX 10.15.7
Sublime 4107

0 Likes

#2

What you want to do is open the Sublime console with View > Show Console, enter sublime.log_input(True), and then press the key that you want to use for toggling comments to see what it’s showing up as. That’s the key to use in your key binding; you want to double check that Sublime is seeing the key the way you think it is, since different keyboard layouts can generate keys in ways you may not expect.

That’s the key (pun mildly intended) thing missing from all of the answers in that SO post, which all outline various key bindings that work without anyone describing how or why they came up with them in the first place.

1 Like

#3

Hi.

Thanks for the response. I did use the console to see what the is bound to.
OSX 10.15.7

Here is my work to comment something out:

  1. Edit/Comment/ Toggle Comment – “CMD + /”
    When I used this method nothing is commented out and the console displays a “#”.

  2. When I go to the console and key the “CMD + /” it displays “super+/” again nothing is commented out.

What should I do next?

0 Likes

#4

The console logs the input that it sees when you having logging turned on like this; for that first one, did you pick the menu entry? The console should display no log output unless you pressed a key, so seeing # seems a little off, unless you actually typed that key.

In addition to the input logging, you may also want to sublime.log_commands(True) and then try again; that will show you not only what key Sublime thought you pressed, but also what command it’s trying to execute.

Lastly, it may be handy to ask what kind of file you’re trying to comment; what the command to toggle comments does depends on the type of file that you’re editing, and not all files support comments (for example Plain Text files do not), so you may be running into something in that area too.

0 Likes

#5

Hi again. I followed your suggestions. Here are the results.

Ok so my text file is a python file per Tool>Build System> Python (checked).

I selected text to comment out.
Go to the menu Edit>Comment>Toggle Comment (cmd+/)
Console displayed this: ‘Command: toggle_comment {"block: false}’
The console input bar remains empty.

I click in the console input box then I used the hotkey ‘cmd+/’ then pressed return.
Console displayed this: ‘Command: toggle_comment {"block: false}’
and a grey ‘#’ appeared.

So the menu and the hotkey are returning the same hotkey command. Yet the comment toggle is not executed in the script. Nothing happens.

Could this be a hotkey conflict with the OS?

0 Likes

#6

Ahh I see, that would explain the # character.

Just to clarify, you should be pressing the key in the file you want to toggle the comment for inside of the place where you want to toggle the comment (it sounds above like you’re doing it in the console input instead).

Regardless, the fact that it works in the console input is an indication that the key is being correctly seen by Sublime and working because the console input is Python.

Note however that Tools > Build System sets the external tool to be executed when you build and has no effect on the type of file that you’re editing. Does the bottom right of the window say Python when you’re editing the file you’re trying to comment?

0 Likes

#7

Ah-ha! I didn’t see the file type there. Oh, man. I wasted so much time on that. Now the comment function works now.

Thanks for your time and attention! - Don

PS lemme know if you have any suggestions to having a python script execute a command line function. Like rsync or mv.

0 Likes