'How to insert a documentation comment in sublime text
In Sublime Text, I know that Ctrl + / comments the current line, and Ctrl + Shift + / inserts a multi-line comment at the cursor.
How to insert a documentation comment of the form
/**
* documentation comment
*/
To do this manually, type /** and press Enter, later close the comment with a /.
How can I do this using a shortcut?
Solution 1:[1]
You can insert a snippet via a key binding (Preferences / Key Bindings):
[
{ "keys": ["ctrl+shift+4"], "command": "insert_snippet", "args": {"contents": "/**\n * $SELECTION\n */"} }
]
Save the settings, and then press Ctrl-Shift-4. If you have a line highlighted, it should be inserted in the right place. But if you have multiple lines selected, it won't properly add asterisks in front of each line.
Solution 2:[2]
As Scovetta noted in their answer, the snippet they presented only works for single-line comments, and I don't think I've ever encountered a single-line documentation comment, as that's just not their intended use.
Instead, I'd highly recommend using the DocBlockr plugin. All you need to do is type /** on an empty line and hit Enter, and it automatically begins each line with *. It also automatically puts */ at the end.
DocBlockr also works with regular comments - just type /* and hit Enter and it automatically inserts a blank new line followed by */.
If you start a doc block on the line just before a function definition, DocBlockr will automatically fill in the parameters:
There are lots of other features too: automatic processing of type hints, // comment reformatting, variable documentation, and more. It's a really useful plugin for C/C++, Java, JavaScript, and other similar languages.
Note: I'm not affiliated with the plugin or its authors in any way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Scovetta |
| Solution 2 | MattDMo |


