How do I create keyboard shortcuts?


#1

Do I have to bother with adding code to some keymap file? Why won’t it let me just edit keyboard shortcuts from the menu like a normal editor?

I’m using the Tabletop Simulator Lua package and I just want a keyboard shortcut for the save and play command.

I’m currently reading about how to code in keyboard shortcuts here: http://flight-manual.atom.io/using-atom/sections/basic-customization/#_customizing_keybindings

I just thought I’d check to see if there’s a better way. Since the command palette is there to show you all the commands with their keyboard shortcuts, surely there should be a way to alter shortcuts directly from the command palette, right?


#2

Not code, no. You do have to add the key sequence and the command.

Why won’t it let me just edit keyboard shortcuts from the menu like a normal editor?

Because that’s not how Atom was designed.

I’m using the Tabletop Simulator Lua package and I just want a keyboard shortcut for the save and play command.

'atom-text-editor':
  'ctrl-alt-s': 'tabletopsimulator-lua:saveAndPlay'

Done. All I had to do to write that was go find the name of the command and then find a key sequence that wasn’t already occupied.

Since the command palette is there to show you all the commands with their keyboard shortcuts, surely there should be a way to alter shortcuts directly from the command palette, right?

Nope.


#3

There are some advantages with the current method:

  • It is more flexible. You can put shortcuts in context, like 'atom-workspace atom-text-editor:not([mini])':
  • It is simple!
  • You can see all your custom key binding at a glance… And they are easy to backup.
  • Atom developers spend less time in designing a complex setting page and more time on important things… :wink:

Inconvenience: indeed, it is a bit less visual / interactive / intuitive. Given that the core target audience are developers, it is a minor point.


#4

Hey, it really worked this time. Thank you kindly.

I had written something almost exactly like that, but I had to guess at the way the command name was formatted internally. I had no idea where to find it.

I can see from your attitude that you think it’s really super easy and that my complaints are unwarranted, but I still think there’s no reason for Atom to forego a more user-friendly design. If we can’t add keyboard shortcuts directly from the menu, we should at least be able to see how a command name is formatted so we can code it in properly.


#5

Thank you kindly.


#6

I’m trying to convey my positivity over how it’s set up to counter the negativity in your first post. Text-based config files are much more friendly to edit than GUI systems, especially if you need to change multiple settings at once. If you want to tweak a language definition in Notepad++, you have to do so much more work than if you want to do the same in Atom.

I still think there’s no reason for Atom to forego a more user-friendly design.

Atom is a code editor designed by coders and for coders. The settings most often customized have a full GUI. For keybindings, it seems like the developers didn’t think that was necessary. I looked and can’t find any packages for managing keybindings, either.

we should at least be able to see how a command name is formatted so we can code it in properly.

That’s normally what Settings -> Keybindings and the keybindings section of the package settings are for, but the package author neglected to add any default keybindings for some reason.


#7

Sorry for being negative. Thanks again!


#8

I can see from your attitude that you think it’s really super easy and that my complaints are unwarranted

Not at all. I wouldn’t mind something more friendly, I just explained why it is not there (yet?) and why I don’t mind the current state.

we should at least be able to see how a command name is formatted so we can code it in properly

I fully agree with this one. Of course, you have the Ctrl+Shift+P command listing all commands, that you can search. It shows “friendly” names for these commands, and a tooltip (not so convenient: cannot be copied) shows the exact syntax.
Listing all the known commands in the keybinding screen, including those without binding, would be a very good idea. With, perhaps, a switch to exclude assigned / unassigned ones… (or sort can be enough there).
After all, an IDE like Eclipse does that.
And manages context is a decent (although still a bit confusing) way.


#9

I didn’t know about the tooltips in the command palette! Thanks.


#10

Because building an understandable UI for things as complex as Atom’s super-flexible keybinding system is really hard :laughing: So rather than not releasing Atom until we could figure out this really hard problem, we did the best we could and released something that worked to get Atom out the door. The best part about shipping even if something isn’t perfect is that we can get the code out in front of a bunch of other smart people who can help give us ideas or even solve the problem with us.

So if you have ideas of how to design something that will work, including what use cases would be covered and which wouldn’t and why, we’d love to hear them! :grinning:


#11

That’s a great idea! Why didn’t I think of that? :wink:


#12

I’m afraid I still don’t understand the complexities of Atom’s super-flexible keybinding system. I’m guessing it has something to do with giving keys different behaviors in different contexts. I’m not sure why an ordinary keyboard shortcuts editor wouldn’t work, perhaps accessed through the edit drop-down menu. But like I said, it would be great to be able to edit a keyboard shortcut directly from the command palette, perhaps by right-clicking a command. It would be great to be able to right-click commands in the dropdown menus as well.

Thanks for all the hard work!


#13

I have system keybindings ctrl-shift-k. But i want assign my short key ctrl-shift-k': 'editor:toggle-soft-wrap'. How to do it?

and please answer - when pressed ctrl-shift-p in any type of file, list show Editor: Toggle soft wrap. But when opening tab keymap.cson line with this command not show. Why?

Thanks


#14

Because you haven’t assigned a keybinding yet. This is covered in the Flight Manual.


#15

of course I’ve seen the manual, but there’s not enough specification and information. So I do not understand what the user will be able to disabled the system keys and assign my short keys. This is a typical problem that happens when use each software… And other details. It’s incredible that Atom understanding the context so much, even if it’s just a configuration file.


#16

If you post a screenshot of your keymap.cson file, I can show you what it should look like to include the keybinding you want to add.


#17

… sometimes my keybindigs work, and some times it is don’t work… it’s spontaneously… I don’t know why


#18

You have a duplicate key. That’s not allowed in CSON.


#19

Everything under .workspace is considered part of .workspace. You haven’t defined anything after that, so you have two ctrl-k entries just like the error message says.

Lines 35 and 36 aren’t going to work at all. You need the CSS selector key like you have for atom-workspace and .workspace.