Sublime Forum

Per-syntax key bindings

#1

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



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

1 Like

#2

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:

sublimetext.info/docs/en/referen … dings.html

0 Likes

#3

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?

0 Likes

#4

Have you tried this?

selector Returns the current scope.

0 Likes

#5

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?

0 Likes

#6

I use this snippet for adding
tag:

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

1 Like