Sublime Forum

Avoid Indent with Snippet Insertion


My plugin inserts a snippet.
I am calling:
view.settings().set(‘auto_indent’,False) before doing the insert.
The problem is… the snippet is still automatically being indented.

When I run the snippet at the start of the line below it always indents the * to be in line with the body text:

  • Someheading
    Some indented text here
    • Snippet inserted header is indented and shouldn’t be!

Does anyone know how to stop this indentation from happening?



You can use self.view.run_command("move_to", { "to": "hardbol" }) before the insert_snippet command (If that’s what you are using to insert the snippet from your plugin). The above command will move your cursor to the start of the line and then insert the snippet.



It was not that my cursor was not positioned correctly.

The snippet inserts a new heading under your existing heading. So it has a newline in the snippet. The problem is that the snippet insertion is not respecting the fact auto_indent is turned off in the view.

I worked around it for now. I insert the newline from the text command that is triggering the snippet in this case. Its frustrating, but works for this case at least.