## Three key bindings for "

### Three key bindings for "

Hi,
in Default (OSX).sublime-keymap I see three key bindings for the double-quotes key.

1.
Why?

2.
Which one is actually used when I press a
Code: Select all
"
(double-quotes character)?

Thanks
bblue

Posts: 26
Joined: Mon Oct 10, 2011 10:35 am

### Re: Three key bindings for "

It depends on the scope the caret's in and the state of Sublime Text. This is defined in the "context" of the key binding.
guillermooo

Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

### Re: Three key bindings for "

Thank you guillermooo, I'm starting to see some light.

If more than one scope/state is satisfied, which one takes the precedence (the first? the last?).

Just to be sure:
Code: Select all
"key": "setting.auto_match_enabled", "operator": "equal", "operand": true

This means that the setting "auto_match_enabled" have to be "equal" to "true"?

Analogously I guess that
Code: Select all
"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true

requires that the current selection be empty… but what does
Code: Select all
"match_all": true
means?

Last, but the most important: where I can learn this kind of stuff (in order to avoid these dummy questions)?

bblue

Posts: 26
Joined: Mon Oct 10, 2011 10:35 am

### Re: Three key bindings for "

guillermooo wrote:Last, but the most important: where I can learn this kind of stuff

I hope this helps:

http://sublimetext.info/

bblue wrote:If more than one scope/state is satisfied, which one takes the precedence (the first? the last?).

They are all required to be true.

bblue wrote:requires that the current selection be empty… but what does
CODE: SELECT ALL
"match_all": true
means?

It means *all* selections need to satisfy the conditions in the context. More on this here:

http://sublimetext.info/docs/en/referen ... -a-context
guillermooo

Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

### Re: Three key bindings for "

Thanks again guillermooo.

I hope this helps: http://sublimetext.info/

Actually not so much… but maybe I have to read it again and again.

They are all required to be true.

Sorry for having been not so clear: I don't mean among contexts, but among key bindings. But maybe they're all mutually exclusive.

It means *all* selections need to satisfy the conditions in the context.

Perfectly clear, thank you!

Just one more question, please please please (this discussion is _very_ informative for me!). Beside to this key binding
Code: Select all
{ "keys": ["\\"], "command": "auto_complete", "context":        [            {"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},            {"key": "selector", "operator": "equal", "operand": "text.tex.latex"}        ] }

I'd like to have another bound to the same keystroke (\) that manage the case of a non-empy selection (so they will be mutually exclusive). In this case the command should be two-fold: an auto_complete followed by an insert_snippet. How to accomplish this?

Cheers
bblue

Posts: 26
Joined: Mon Oct 10, 2011 10:35 am

### Re: Three key bindings for "

bblue wrote:Actually not so much… but maybe I have to read it again and again.

Maybe I can change something too ;) Anything particulary unclear for you?

bblue wrote:Sorry for having been not so clear: I don't mean among contexts, but among key bindings. But maybe they're all mutually exclusive.

As long as the contexts are different, they should not step on each other, yeah.

bblue wrote:I'd like to have another bound to the same keystroke (\) that manage the case of a non-empy selection (so they will be mutually exclusive). In this case the command should be two-fold: an auto_complete followed by an insert_snippet. How to accomplish this?

In ST1 there used to be a 'sequence' command that would let you run a series of commands. I don't think that's so simple in ST2 now; you'd need to code your own plugin. But by the look of it, your might be better off using other features like .sublime-completions files to do what you're after. To be honest, I don't think I understand what you want to do! ;)
guillermooo

Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

### Re: Three key bindings for "

Maybe I can change something too Anything particulary unclear for you?

This is more than I may ask! Give me a couple of days and I'll tell you. I prefer reading it again before.

To be honest, I don't think I understand what you want to do!

Let me explain.
Suppose a sublime-completion file like this:
Code: Select all
{    "scope": "text.tex.latex",    "completions":    [        { "trigger" : "\\bf",      "contents": "\\textbf{${1:[text]}}"}, { "trigger" : "\\it", "contents": "\\textit{${1:[text]}}"}    ]}

Now, with the key binding
Code: Select all
{ "keys": ["\\"], "command": "auto_complete", "context":        [            {"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},            {"key": "selector", "operator": "equal", "operand": "text.tex.latex"}        ]}

when (in a TeXT/LaTeX file) I press the backslash when there is no selection an auto-completion menu appears, that give me the option to choose between "\bf" and "\it". If, say, I choose the second, the following text will appear:
Code: Select all
\textit{[text]}

where the "[text]" is selected, ready to be replaced with what I want. So far so good.

What I really like to accomplish is to manage the situation in which there is a selection when I press the backspace. Say "actual text." The result now should be that when I select "\it" from the auto-completion menu, the following text appears:
Code: Select all
\textit{actual text}

Clear enough?
bblue

Posts: 26
Joined: Mon Oct 10, 2011 10:35 am

### Re: Three key bindings for "

bblue wrote:What I really like to accomplish is to manage the situation in which there is a selection when I press the backspace. Say "actual text." The result now should be that when I select "\it" from the auto-completion menu, the following text appears:

Not exactly what you want, but close:

Code: Select all
{    "scope": "text.tex.latex",    "completions":    [        { "trigger" : "\\bf",      "contents": "\\textbf{${1:$SELECTION}}"},        { "trigger" : "\\it",      "contents": "\\textit{${1:$SELECTION}}"}    ]}

This way you only need a key binding.

Also, you can read through this topic:

viewtopic.php?f=3&t=3390
guillermooo

Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

### Re: Three key bindings for "

Not exactly what you want, but close:

It works perfectly as far as I select an item with the mouse from the auto-completion menu. But it doesn't work if I use the keyboard for a fuzzy-search of the list (which, in the real-life, is muuuuch longer than the two-items list I gave you as an example…).

So, there is no way to assign a list of commands to a key instead of a single one?

Also, you can read through this topic

Sure I will, thank you.
bblue

Posts: 26
Joined: Mon Oct 10, 2011 10:35 am

### Re: Three key bindings for "

Yeah, you were talking about "selecting" items, so I assumed you weren't using the fuzzy search. As soon as you type something in, the previous selection's text will obviously be wiped away.

You can still do what you want, but not through the completions list, I believe. You definitely can do it with separate key bindings as explained in the linked post.

Maybe the snippet syntax could be expanded to allow for a place holder to be inserted when a $VARIABLE was empty, like in: Code: Select all ${1:\$SELECTION:{[text]}}
guillermooo

Posts: 729
Joined: Thu Jul 23, 2009 9:06 am