Riveascore
Riveascore

Reputation: 1852

Sublime Text custom comment behavior

How do I change Sublime Text's toggle comment and block comment characters used in a particular file type?

For instance, in erb files, I want:⌘ + / to apply:

<%
=begin

<div>All my html/erb content</div>

<%
=end %>

Instead of it's current functionality which still allows erb tags to seep through and break things:

<!--
<div>All my html/erb content</div>
-->

Upvotes: 2

Views: 1024

Answers (1)

MattDMo
MattDMo

Reputation: 102852

If I understand you correctly, you want to be able to select

puts "This is embedded Ruby!"

for example, hit /, and now have it look like this:

<%
=begin
puts "This is embedded Ruby!"
=end %>

If that is the case, then create a new XML file with exactly the following contents, including newlines, etc.:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>text.html.ruby</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START</string>
                <key>value</key>
                <string>&lt;%
=begin
</string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_END</string>
                <key>value</key>
                <string>
=end %&gt;</string>
            </dict>
        </array>
    </dict>
    <key>uuid</key>
    <string>4C2E088A-2EDB-44AB-9C62-CE0112B4C237</string>
</dict>
</plist>

Save the file as Packages/Rails/HTML (Rails) Comments.tmPreferences, where Packages is the folder opened when selecting Preferences -> Browse Packages.... On OS X it's ~/Application Support/Sublime Text X/Packages where X is either 2 or 3, depending on the version of Sublime you're using. If you're using ST2, the Packages/Rails folder will already exist, so you can just save the file straightaway. On ST3, Packages/Rails (most likely) doesn't exist yet, so you'll have to create it first, then save the file.

Good luck!

Upvotes: 3

Related Questions