-1

I'm coding some python files with sublime and I'd like to comment multiple selected lines which means putting the character '#' at the beginning of each selected line. Is it possible to create a such shortcut-key Binding on sublime to do that ?

Thanks Vincent

  • 1
    Possible duplicate of [Keyboard shortcut to comment lines in Sublime Text 3](http://stackoverflow.com/questions/17742781/keyboard-shortcut-to-comment-lines-in-sublime-text-3) – l'L'l Aug 28 '16 at 19:00
  • 1
    The `comment` command is linked to the `Ctrl-/` keybinding (hold down `Ctrl` while pressing `/` once). – MattDMo Aug 28 '16 at 19:24
  • @l'L'l The accepted answer to that question is incorrect. There was a bug in ST3 over **3.5 years ago** that has long-since been fixed. The `Ctrl-7` and `Ctrl-Shift-7` shortcuts were a workaround for the German QWERTZ keyboard, which is a different issue. – MattDMo Aug 28 '16 at 19:30
  • @MattDMo: The question being a possible duplicate was mostly what I was bringing attention to, and wasn't aware of the info you mentioned ( good to know ). It might not be relevant as to the answer being correct either I suppose, and unfortunately I see that happen once in a while, especially when the "duplicate" question is older/dated. – l'L'l Aug 28 '16 at 19:42
  • 1
    @l'L'l no prob. I have dupe hammer powers in all the sublime tags, as well as in python, so I'll see if I can find another suitable target. Feel free to @ reply to me here if you find one first, I'm going out for a while. Thanks for the help. – MattDMo Aug 28 '16 at 19:44

2 Answers2

0

To comment code with sublime text3 you can use the existing shortcut, which is bound to Ctrl-/

If you want to change that shortcut, you can edit your keyboard user settings and add this line:

{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } }

In the previous line you can see how that command would be bound to ctrl+7

BPL
  • 9,632
  • 9
  • 59
  • 117
  • There's absolutely no reason to. Commenting is already bound to `Ctrl-/`. – MattDMo Aug 28 '16 at 19:26
  • @MattDMo I know, but OP asked explicitely by `Is it possible to create a such shortcut-key Binding on sublime to do that`, he didn't mention anything about using some existing one – BPL Aug 28 '16 at 19:33
  • 1
    Many times, what the OP is asking and what the best solution is turn out to be different. They may be asking how to foo the bar using baz, but, upon further inquiry, it may become quite clear that they don't even need to foo the bar at all. There may *be* a way to foo a bar using baz, but that particular OP didn't need to, so that was the best solution. – MattDMo Aug 28 '16 at 19:35
  • @MattDMo That's a pretty solid argument, I buy it, +1 – BPL Aug 28 '16 at 19:37
0

You can put three times ' in the front of your commented block and three times at the end.

''' This is
a multi-line
comment '''
Tristan
  • 2,000
  • 17
  • 32
  • This makes a string, not a comment - they are not the same thing. Always use comments when you mean to comment something, and use strings when you need a string. – MattDMo Aug 28 '16 at 19:25