Sublime Forum

Newline in a snippet without auto-indenting?

#1

Hi all,
I’m curious if anyone know if there’s a way to insert a snippet that contains multiple newlines while being able to remove the auto indenting from new lines (but still indenting tabs to the correct level)?

I’ll give an example. I have a javascript snippet that inserts the following code:

[code]${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}: function(${1:args}) {
var instance = this;

$0

}${2:,}[/code]

var instance = this; and $0 should both be indented to the correct level, but what happens for me is that the empty line gets tab characters in it that I have to manually remove.

Is there a way to disable this?

Thanks in advance,

1 Like

#2

Hello natecavanaugh
Try following one it give me

import pdb
pdb.set_trace()

pdb
1 Like

#3

not sure why this has been necro’d, but if you take a look at some default JS snippets like https://github.com/sublimehq/Packages/blob/9fec9a5ec1fb96b52097fe3d9f8a1fa0834947c3/JavaScript/Snippets/function-(fun).sublime-snippet you’ll see that auto indentation isn’t applied to the lines in the snippet when the snippet is inserted.

1 Like

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

I created a command for it:

import sublime_plugin

class RichPlainTextForceInsertNewlineCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        view = self.view
        settings = view.settings()

        auto_indent = settings.get('auto_indent', True)
        if auto_indent: settings.set('auto_indent', False)

        for selection in view.sel():
            view.insert(edit, selection.a, '\n')

        if auto_indent: settings.set('auto_indent', True)
[
	{ "caption": "Rich Plain Text: Force Insert New Line", "command": "rich_plain_text_force_insert_newline" },
]
0 Likes