Home Download Buy Blog Forum Support

Per-syntax key bindings

Per-syntax key bindings

Postby optilude on Tue Aug 09, 2011 9:50 pm

Hi,

Is it possible in ST2 to define a keybinding (in a plugin) that is only enabled for a particular syntax? Basically, I'm writing a plugin to integrate http://pypi.python.org/pypi/mr.igor so that when I press cmd+i it'll run the igor command. I've got a plugin folder with a Default (OSX).sublime-keymap with:

Code: Select all
[

  { "keys": ["super+i"], "command": "igor_replace" }

]


This works, but I gather this means cmd+i is taken over across ST2, not just when the Python syntax is in effect.

Martin
optilude
 
Posts: 30
Joined: Sun Jan 30, 2011 2:36 pm

Re: Per-syntax key bindings

Postby ehamiter on Tue Aug 09, 2011 10:28 pm

http://sublimetext.info/docs/en/customi ... dings.html

Look at Contexts near the bottom. Caveat: there's a mix of ST1 and ST2 info on this particular web address, but I think what you're looking for is there.

Full info here:

http://sublimetext.info/docs/en/referen ... dings.html
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Per-syntax key bindings

Postby optilude on Tue Aug 09, 2011 11:43 pm

I saw that, but I don't see what context argument would allow me to match on the syntax (or file extension) of the current buffer?
optilude
 
Posts: 30
Joined: Sun Jan 30, 2011 2:36 pm

Re: Per-syntax key bindings

Postby ehamiter on Wed Aug 10, 2011 2:06 am

Have you tried this?
Code: Select all
selector
    Returns the current scope.
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Per-syntax key bindings

Postby optilude on Wed Aug 10, 2011 2:17 am

I don't understand how I'd use that. It's not quite clear what 'scope' means here, or how I match against it. Any examples?
optilude
 
Posts: 30
Joined: Sun Jan 30, 2011 2:36 pm

Re: Per-syntax key bindings

Postby iamntz on Wed Aug 10, 2011 4:13 am

I use this snippet for adding <br/> tag:

Code: Select all
   {
      "keys": ["ctrl+shift+enter"],
      "command": "insert_snippet",
      "args"   :   {
         "contents": "<br/>"
      },
      "context":[
         { "key": "selector", "operator": "equal", "operand": "text.html" }
      ]
   },


(you can put it in Default.subilme-keymap to have the same shortcut for all OS)
iamntz
 
Posts: 918
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests