Sublime Forum

Accept autocomplete and go beyond ending quote

#1

Is there a keybind to accept an autocomplete, and have your cursor moved beyond the ending quote? For example, if I’m writing HTML and type name=" an ending quote is placed beyond my cursor. If I type in my name,either manually or by autocomplete, I want to move past the ending quote. As is, I’m moving my hand off home row and hitting the right arrow key to get past it.

I’m sure there’s an easier way to do this… Any help would be appreciated!

0 Likes

#2

You could create a macro that runs command “insert_best_completion” and “move” by: characters forward: true and bind it to a key (tab/enter/alt+tab whatever) so that it only triggers inside quotes in HTML.

EDIT: or you could just type the closing quote.

0 Likes

#3

Add the following to your User Keybindings: [code] { “keys”: “enter”], “command”: “move”, “args”: {“by”: “characters”, “forward”: true}, “context”:

    { "key": "following_text", "operator": "regex_contains", "operand": "^)\"'\\]\\};]", "match_all": true },
    { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]   

},[/code]

0 Likes

#4

[quote=“C0D312”]Add the following to your User Keybindings: [code] { “keys”: “enter”], “command”: “move”, “args”: {“by”: “characters”, “forward”: true}, “context”:

    { "key": "following_text", "operator": "regex_contains", "operand": "^)\"'\\]\\};]", "match_all": true },
    { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]   

},[/code][/quote]

This is why I love Sublime Text.

0 Likes

#5

That is awesome! You know, thanks to this, I’m purchasing a license the next time it bugs me about it. Every time that message has appeared, I’ve said yes, and stared at the purchase page for a few minutes mulling it over. I’m done mulling, and will be purchasing.

ST2 has replaced Notepad++ on my home and work computers. Probably going to make a portable one sit on my thumbdrive too.

0 Likes

#6

This is awesome and just what I was looking for. Now ST2 tabs out of quotes and brackets. However, this has introduced a new problem for me. When using snippets the tab out of “()” is overriding my snippet tabs. For instance, here is what I use for a function snippet:

function ${1:function_name}(${2:argument}){ ${0:// body...} }

The problem is here : ${2:argument}. After entering my arguments, I can’t tab to the body as the key binding from in earlier in the thread overrides the the snippet and just moves the cursor to the other side of the “)”.

Is there anyway to have the above key binding work except when followed by a curly brace “){” ? or something like that? I really wish I was better at these key bindings, as it’s supremely helpful. Thanks.

0 Likes

#7

Seems I found a solution:

{ "key": "has_next_field", "operator": "equal", "operand": true }

Makes sense.

0 Likes

#8

Actually, no. Only works if there if the code hint box is open. :imp:

0 Likes