Home Download Buy Blog Forum Support

Add keystroke for a menu item/command

Add keystroke for a menu item/command

Postby handycam on Tue Jan 17, 2012 5:01 pm

This might be a stupid question, but how do I find the internal name for a given command (in a menu) so I can add a key command to my config?

I have one such, but jps told me the command name:

Code: Select all
  { "keys": ["shift+alt+command+p"], "command": "scope_to_clipboard"  }


I'd like to add a command from the Tag plugin.
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Add keystroke for a menu item/command

Postby facelessuser on Tue Jan 17, 2012 5:06 pm

I think what you need to do is look in the Tag plugin source file and look at the class name.

Sublime Text commands are from the class name of certain classes. They are always in the form
Code: Select all
WhateverNameCommand
. Notice they always end in command. So then you just replace the camel case with underscores and lower case and remove command.

Code: Select all
whatever_name
facelessuser
 
Posts: 1572
Joined: Tue Apr 05, 2011 7:38 pm

Re: Add keystroke for a menu item/command

Postby handycam on Tue Jan 17, 2012 6:03 pm

Thank you. Found the command.


Code: Select all
  { "keys": ["shift+ctrl+r"], "command": "tag_remove_picked_in_selection"  }


How can one be sure a keystroke is not infringing on an existing one?
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Add keystroke for a menu item/command

Postby facelessuser on Tue Jan 17, 2012 6:54 pm

This is much more difficult. You basically have to search the keymap files of ST2.

I personally, on plugins that I release, try to bind all of my commands to a sequence. I use "ctrl+shift+b". So everything is ["ctrl+shift+b", "ctrl+shift+something else"]. That way I am only taking one shortcut away and just building combinations off of that.

ST2 uses so many shortcuts that it is becoming increasingly more difficult to find shortcuts. Taking into account all of the plugins that you may install that eat up more shortcuts, it is hard to say which are free.

That is why I also have started to shy away from releasing plugins with shortcuts defined. Instead I create commands in the command palette and let the user create a shortcut if they really want one.

If you are writing a command or plugin for personal use, then you can overwrite shortcuts that you don't use, but if you plan on releasing it, you have to be very more careful.
facelessuser
 
Posts: 1572
Joined: Tue Apr 05, 2011 7:38 pm

Re: Add keystroke for a menu item/command

Postby handycam on Tue Jan 17, 2012 7:52 pm

Yes, it would be nice, in the future perhaps, if the app could do a "dump" of all key configs and their commands, to a text file/window. So users can refer to it.
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Add keystroke for a menu item/command

Postby C0D312 on Tue Jan 17, 2012 8:09 pm

In your console, type:
Code: Select all
sublime.log_commands(True)
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am


Return to General Discussion

Who is online

Users browsing this forum: roy and 23 guests