Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 Comment/Doc Block

Recently, I decided to try out Sublime Text 2 as a TextMate alternative (which it is). I'm absolutely loving it but the only issue that bugs me is that it doesn't continue the PHP Comment/Doc Block upon pressing "Enter".

It just adds new blank lines instead of lines starting with "* " as seen here http://cl.ly/AFcP/o

Is there a solution to this? I tried doing a key binding for it but it was just too complicated for me, especially because I'm not too experienced with the editor.

Thanks in advance.

like image 846
Taha Avatar asked Sep 19 '11 22:09

Taha


People also ask

How do you comment multiple lines in Sublime Text?

In Sublime Text 2 it was possible to comment out a line or a block of lines with Ctrl + / and Ctrl + Shift + / .

How do I insert multiple lines in Sublime Text 3?

To add single-line comments, put the text cursor on the line to comment-out or highlight multiple lines and type CMD + / on Mac, for Linux and Windows use CTRL + / .


2 Answers

And now an even better solution has become available:

https://github.com/spadgos/sublime-jsdocs

It is called DocBlockr, and it has PHPDoc support. It automatically adds the doc block based on the function parameters. Nice...

like image 65
Clint Avatar answered Oct 03 '22 15:10

Clint


Just had the same problem and wrote a little snippet. Since it is a keybinding it has to be stored in a .sublime-keymap File. If you're on a Mac just goto Sublime Text 2 > Preferences > Key Bindings - User or similar on some other OS.

Here is my Code:

[ {"keys": ["enter"], "command": "insert", "args" : {"characters": "\n * "}, "context": [     {"key": "selection_empty", "operator": "equal", "operand": true},     {"key": "preceding_text", "operator": "regex_contains", "operand": "\\/\\*\\*$", "match_all": true} ]}, {"keys": ["enter"], "command": "insert", "args" : {"characters": "\n* "}, "context": [     //{"key": "selection_empty", "operator": "equal", "operand": true},     {"key": "preceding_text", "operator": "regex_contains", "operand": "^[\t ]*\\*[^\\/]", "match_all": true} ]} ] 
like image 37
Handfeger Avatar answered Oct 03 '22 15:10

Handfeger