Sublime Forum

Nicely formatted titles/headings in txt file

#1

Hello,

I have just started my adventure with sublime text. When I write my programs in python in sublime I like to leave nice looking comments. Sth. like this:

############################
### This is heading no 1 ###
############################

Is there a way to automate this in sublime? I think the most preferable solution would be when I have title on it’s own (f.e. above ‘This is heading no 1’) and cursor at the end of the line pressing keyboard shortcut which would launch snippet/makro which would:

1)add 3 hash tags at the beginning of the line
2)add 3 hash tags at the end of the line
3)add (len(text) + 24) hash tags in line above
4)add (len(text) + 2
4) hash tags in line below

I would be grateful for pushing me in the direction of possible solution.

Thank you in advance for help.

0 Likes

#2

With a simple snippet you can have something without the ### aligned at the end of your second line:
Copy the following in a file with the extension sublime-snippet in your user-package directory:

<snippet>
   <name>Comment Box</name>
   <content><![CDATA[############################
###  ${0}  ###
############################]]></content>
    <tabTrigger>###</tabTrigger>
    <scope>source.systemverilog</scope>
</snippet>

You will need to press ctrl+space after the triple # to have the auto-completion appears

If you need something matching exactly your need, you would need to write a very simple plugin.

1 Like

#3

For the time being snippet will be good.

Thank you for help!

0 Likes

#4

And maybe have a look at https://packagecontrol.io/packages/CommentBanner, this might match your need (never test myself).

0 Likes

#5

Here’s a snippet I use for something similar. You can easily adapt it to your needs:

<snippet>
<description>Heading 1</description>
<tabTrigger>h1</tabTrigger>
<scope>text.html.markdown, text.restructuredtext</scope>
<content><![CDATA[
${1/./=/g}
${1:Heading 1}
${1/./=/g}
]]></content></snippet>
1 Like

#6

This snippet is all what I want. I played a little bit to understand what it is doing and now I am able to create may own. Thank you!

0 Likes