Sublime Forum

How to prevent block $SELECTION in snippet from adding indentations?

#1

I’m trying to create a custom comment using $SELECTION. By using only $SELECTION…

<div>
  <p>hi</p>
</div>

transforms into

<div>
      <p>hi</p>
    </div>

How do I retain the original tabs as the original?

1 Like

#2

I can’t replicate this on build 3140

snippet:

<snippet>
    <content><![CDATA[
$SELECTION
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

document, syntax set to HTML:

<div>
  <p>hi</p>
</div>

steps followed:

  • select all
  • open command palette
  • Snippet: SELECTION
  • caret moves to end of selection, indentation remains unaffected
1 Like

#3

Sorry, I should have been more specific.

I’m using babel sublime, and it occurs within JSX elements.

function foo() {
  return (
    <div>
      <p>hi</p>
    </div>
  )
}

Everything works fine outside the JSX statement.

Any idea as to why this may be happening?

Build 3126

Thanks

1 Like

#4

thanks for the example, I can confirm that I get the same behavior - I wonder why, because when I tried a different snippet, it didn’t auto indent (though maybe that was due to the line that would get indented being a comment?)
I’ll try to explore it further when I get time, it may be that one will need to hook into the insert_snippet command to set smart_indentation to false before the command is triggered, and back to true again afterwards, to work around it

1 Like

#5

How do you add code to a snippet? Could you point me to an example?

1 Like