How to map a package's command to keymap?


#1

How do I find out the exact name of a command in a package so that I can add it to my keymap?

For example, I have the SFTP Deployment package and would like to map “upload open files” to a key command.


#2

If you can find the command in the Command Palette, then you can easily transform the Command Palette format to command format by:

  1. Change everything to lowercase
  2. Remove the space after the colon
  3. Convert other spaces to hyphens

For example:

  • “Foo Bar: Baz Quux” becomes foo-bar:baz-quux

Custom context menu without creating a package
#3

Do these still go under .editor?

Because the 2 new ones I just added don’t work…

'.editor:not(.mini)':
   'alt-enter': 'editor:insert-br'
   'alt-space': 'editor:insert-nbsp'
   'ctrl-u': 'sftpdeployment:uploadcurrentfile'
   'ctrl-alt-u': 'sftpdeployment:uploadopenfiles'

#4

It looks like you missed Step 3: Convert other spaces to hyphens.


#5

Doh! Indeed I did, sorry


#6

Still no love, though:

'.editor:not(.mini)':
   'alt-enter': 'editor:insert-br'
   'alt-space': 'editor:insert-nbsp'
   'ctrl-u': 'sftp-deployment:uploadcurrentfile'
   'ctrl-alt-u': 'sftp-deployment:uploadopenfiles'

where the commands are listed as such:


#7

It looks like they’re not following the standard. Try the following: sftp-deployment:uploadCurrentFile

Step 2 should probably be, “Convert first characters in words to lower case”.


#8

That was it.

I assume they should have have spaces in their commands, in which case your original instructions would have worked? And since they used Camel Case, I need to use it too?


#9

Yes, that’s correct.


#10

To find out what commands a package uses:

  1. Open Atom Package Settings View, find package from left sidebar, see “Keybindings” section.
    OR
  2. Take a look at the packages keymaps/package-name.cson file

#11

That will work if they have mapped commands to keys already. But if they haven’t, then the simplest way to discover them without going code spelunking is to look at the Command Palette.

With this in mind, I’ve created atom/settings-view#165 to request an easier way to discover commands that do not come pre-configured with keybindings.


#12

Here’s what you need:

'atom-workspace':
  'ctrl-alt-u': 'sftp-deployment:uploadCurrentFile'

You need to have “atom-workspace” for the class. If you’re in doubt about what command to use, open up the preferences, click on Open Config Folder, open the “packages” folder, then the folder for the relevant package. Inside there, open the Menus folder, and click the file inside there. You’ll see all the commands used in any menus, either in the menu bar or in a contextual popup menu. Some packages don’t have any preset keybindings, so looking for a Keybindings folder won’t help you.