Home Download Buy Blog Forum Support

Key bindings with conditional statements?

Key bindings with conditional statements?

Postby fort on Sat May 11, 2013 5:50 pm

Hi,

I'm trying to set up context-sensitive key bindings, but I haven't found anything relevant in the documentation, and I'm missing a necessary environment variable. An example would be the following, for the key binding super+b :

    a) if some text is selected, it expands to \textbf{$SELECTION}$0
    b) if no text is selected, it expands to \textbf{"adjWord"}$0, where "adjWord" is a name I made up for whatever word the cursor is currently adjacent to.

So far, I've only been able to do (a):

Code: Select all
{ "keys": ["super+b"], "command": "insert_snippet", "args": { "contents": "\\textbf{$SELECTION}$0" } }


So, I have two questions: 1) how do I set up a conditional statement? and 2) is there an environment variable that does what I'm using "adjWord" for above?

Cheers,
fort
fort
 
Posts: 2
Joined: Sat Apr 27, 2013 12:04 am

Re: Key bindings with conditional statements?

Postby iamntz on Sat May 11, 2013 6:06 pm

iamntz
 
Posts: 819
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Key bindings with conditional statements?

Postby fort on Sat May 11, 2013 7:01 pm

Thanks, I'd read that but I can't find any examples of what I'm looking for. Btw, I'm an ST2 n00b (in case it wasn't obvious ;) so I'll need a bit of explicit guidance,.
fort
 
Posts: 2
Joined: Sat Apr 27, 2013 12:04 am

Re: Key bindings with conditional statements?

Postby skuroda on Sat May 11, 2013 7:53 pm

The default key bindings, along with unofficial docs are your friends for figuring out some of the context stuff. For your case, I would take a look at the auto pair functionality. That would have pointed you to the following context.

Code: Select all
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }


It's also listed as a context entry in the unofficial docs, but seeing it used (as in the default keybindings) is sometimes more helpful.

http://docs.sublimetext.info/en/latest/ ... -a-context

If you want to change the contents of "adjWord" (without modifying the snippet), you will probably have to run it through a plugin.
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 20 guests

cron