jason-kane/PyYapf

Support custom key bindings

Closed this issue · 15 comments

Please add support for custom key bindings.

Sure. I'll need to figure out how, but it doesn't look particularly difficult.

You can just go to Preferences -> Key Bindings and add your favorite key bindings for theyapf_selection and yapf_document commands.

(The syntax is the same as in the three .sublime-keymap files in the repository.)

Other packages have their key bindings next to their package settings, which is quite convenient.

@catch22 I tried putting this in my sublime-keymap file and it doesn't seem to work:

    {
    	"keys": ["super+option+a"], "command": "yapf_document",
    	"context":  [{"key": "selector", "operator": "equal", "operand": "source.py"}]
    }

Maybe user error?

Pretty trival to add:
https://github.com/SublimeGit/SublimeGit/blob/master/Main.sublime-menu#L28

but it looks like that won't solve your problem, just make it easier to open the keymap file.

http://docs.sublimetext.info/en/latest/reference/key_bindings.html is a bit internally inconsistent. "option" isn't listed as a valid modifier but it is used in an example -- of what not to do.

Replaced "option" wtih "alt", still doesn't seem to work.
Does something similar work for you?

Did you add [...] around it?

Try copying and adapting our .sublime-keymap file (assuming it works...).

Figured it out. It needed to be source.python, not source.py.
Here's what works:

    {
    	"keys": ["super+lalt+a"], "command": "yapf_selection",
    	"context":  [{"key": "selector", "operator": "equal", "operand": "source.python"}]
    }

I think we should keep this issue open because AFAIK there's currently no way to remove the default key bindings, just adding new ones. Also the convenience of having the package's key bindings show up in the normal spot in the menu would be nice.

I don't think you need the context part -- the yapf_selection (etc.) command only runs when the view contains Python code.

I added menu entries for the README & the Key Bindings (and also improved the Settings one). Looks good?

looks good to me

Released as v0.13.0, nicely done.