Sublime Forum

Improved Comments and Comment Banners

#1

I’m surprised the comments function in Sublime Text 2 isn’t more intuitive. ‘Toggle Comments’ works fine for toggling existing comments, but it works poorly for inserting new comments. For example if a comment is not present I expect the Toggle Comments keyboard shortcut to place my cursor in the middle of the comment tags e.g. /* */

I’d also really like to see a comment banner feature like TextMate’s, where I can easily mark key sections with a big comment banner like this…

/------------------------------------------- HEADINGs -------------------------------------------/

0 Likes

#2

I’d also love to see something like TextMate’s comment banner functionality, hitting CTRL+SHIFT+B gives you a nice way to make a more obvious, 3 line comment along the lines of:

// --------------------- // --- GLOBAL STYLES --- // ---------------------

where the top and bottom lines are auto-sized based on the string in the middle and the comment type is scope-aware.

0 Likes

#3

Tweak as needed:

<snippet> <content><![CDATA[==${1/./=/g} = ${1:Your Comment Goes here} ==${1/./=/g}]]></content> <tabTrigger>comm</tabTrigger> <scope>text.plain</scope> </snippet>

0 Likes

#4

Note that Sublime Text doesn’t seem to be very resilient to malformed snippets at the moment. It just crashed on me now because I made a typo while testing the snippet above.

0 Likes

#5

I’ve noticed that comments arent very good in Sublime as well.

Mainly when I try to comment code in source.HTML I get PHP style comments instead of HTML ones, which is very annoying. I assume it’s based on the file type, not the current region source?

0 Likes

#6

Awesome, thanks!

0 Likes

#7

jbrooksuk, .tmPreferences files, where comment-toggling is defined, do let you specify scope selectors. That makes me think they are not (only) bound to file types. But I haven’t really tested… In the past there were many glitches with comment toggling, but at least for Python the situation seems to have improved.

0 Likes