Sublime Forum

Three key bindings for "

#1

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

Why?

Which one is actually used when I press a " (double-quotes character)?

Thanks

0 Likes

#2

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.

0 Likes

#3

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:

"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

"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true

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

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

:smile:

0 Likes

#4

I hope this helps:

sublimetext.info/

They are all required to be true.

[quote=“bblue”]requires that the current selection be empty… but what does
CODE: SELECT ALL
“match_all”: true
means?[/quote]

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

sublimetext.info/docs/en/referen … -a-context

0 Likes

#5

Thanks again guillermooo.

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

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

Perfectly clear, thank you!

Just one more question, please please please (this discussion is very informative for me!). Beside to this key binding

{ "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

0 Likes

#6

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

[quote=“bblue”]Sorry for having been not so clear: I don’t mean among contexts, but among key bindings. But maybe they’re all mutually exclusive.
[/quote]

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

[quote=“bblue”]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?
[/quote]

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! :wink:

0 Likes

#7

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

Let me explain.
Suppose a sublime-completion file like this:

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

Now, with the key binding

{ "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:

\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:

\textit{actual text}

Clear enough?

0 Likes

#8

Not exactly what you want, but close:

[code]{
“scope”: “text.tex.latex”,
“completions”:

    { "trigger" : "\\bf",      "contents": "\\textbf{${1:$SELECTION}}"},
    { "trigger" : "\\it",      "contents": "\\textit{${1:$SELECTION}}"}
]

}[/code]

This way you only need a key binding.

Also, you can read through this topic:

0 Likes

#9

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?

Sure I will, thank you.

0 Likes

#10

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:

${1:$SELECTION:{[text]}}
0 Likes