I'm getting started with customizing the Atom Editor and have gotten stumped attempting to change the key mapping for Tree View:Toggle.
I put this in my user keycap.cson file:
'.editor':
'ctrl-t': 'Tree View:Toggle'
But it doesn't work.
Looking at Preferences->Keybindings I see it listed as I'd expect:
ctrl-t Tree View:Toggle User .editor
What did I do wrong?
Update:
Changing to:
'.editor':
'ctrl-t': 'tree-view:toggle'
didn't fix the problem.
The Key Binding Resolver shows that the command was recognized, but it didn't toggle the tree view. See this screenshot:
http://cl.ly/image/3A2X1p350v2Q
Any other thoughts on this?
Press ctrl-\ or cmd-\ to open/close the tree view and alt-\ or ctrl-0 to focus it.
Go to Edit -> Preferences -> Keybinding, and click on the link at the top of the page to "your keymap file". (Obviously, replace the shortcut and the command with what you want.) Done!
There are several ways to open a file in Atom. You can do it by choosing File > Open from the menu bar or by pressing Ctrl+O to choose a file from the standard dialog.
I went through the same problem! It was a pain in the ass because i needed to use my own shortcuts but atom's keybinding are different from my latin-qwerty-keyboard, so while playing around with atom and looking for some good information, i came out with this solution:
Problem:
When i type in my windows Ctrl-Alt-\ Atom's keybinding is Ctrl-Alt-]
Or if i want '@' i need to type Ctrl-Alt-q but Atom's keybinding does this 'autoflow:reflow-selection' instead.
Solution:
1._ Go to Settings->Keybindings. Once you're there, in the search bar, find the keybinding you want to change. For example if i want to change Ctrl-Alt-q, so i type: Q and it'll filter all keybindings with this letter.
2._Then to modify it, click int the copy&paste small-icon next to the keybinding you want to modify, it is at Keystroke column. (it will copy the code lines that you need so that you can modify it)
3._ Once you copied the keybinding, go to File->Open Your Keymap and it'll open a tab with the keymap.cson file. Put your cursor at the end and paste there the lines you copied in step#2. It should show something like this:
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-alt-q': 'autoflow:reflow-selection'
4._ Now you can change atom's behavior. I'll erase 'autoflow:reflow-selection' and write 'unset!' so that it shows the arroba.
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-alt-q': 'unset!'
Now when i type Ctrl-Alt-q in atom editor it shows the arroba, finally! If you want it to do something else, instead of writting 'unset!' you just need to put whatever you want it to do.
Note: If you want to know the atom's keybindings so that you can change some of them, use the keybinding resolver, go to Packages->Keybinding Resolver->Toggle.
Here i post the changes i did in my keymap.cson in order to use my atom editor with my latin-qwerty-keyboard.
'atom-workspace atom-text-editor:not([mini])':
"ctrl-alt-[": "unset!",
"ctrl-alt-]": "unset!",
'ctrl-/': 'unset!'
'ctrl-7': 'editor:toggle-line-comments'
'ctrl-alt-8': 'tree-view:recursive-collapse-directory'
'ctrl-alt-8': 'editor:fold-current-row'
'ctrl-alt-9': 'editor:unfold-current-row'
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-alt-q': 'unset!'
'.platform-win32 .find-and-replace, .platform-linux .find-and-replace':
'ctrl-alt-/': 'unset!'
'ctrl-alt-7': 'find-and-replace:toggle-regex-option'
'.platform-win32 .project-find, .platform-linux .project-find':
'ctrl-alt-/': 'unset!'
'ctrl-alt-7': 'project-find:toggle-regex-option'
Cheers!
This is easy enough to fix. You haven't correctly formatted the name of the command. It should look like the following:
'.editor':
'ctrl-t': 'tree-view:toggle'
In the future, if things aren't working as expected, try checking out existing open source packages that you know are working and see if you can find a mismatch. For instance, you can go to the tree-view's keymap file, tree-view.cson
, to see how they have formatted it.
Further Improvements
You might notice that because the keybinding you have defined is tied to the editor, if you have the Tree View in focus, your keybinding won't be triggered. Again, looking at the file above, you will see a way to improve this. Tie the keybinding to the platform, .platform-darwin
(or whichever is appropriate for you), so that it is triggered no matter which element of the editor is in focus.
'.platform-darwin':
'ctrl-t': 'tree-view:toggle'
This, of course, raises a different issue. Now, when the editor is in focus, the existing keybinding for editor:transpose
will take precedence because of its more specific CSS class (namely, .editor
). Thus, the Tree View will not be toggled now when the editor is in focus. The easiest way to fix this is add the keybinding for the editor as well:
'.platform-darwin':
'ctrl-t': 'tree-view:toggle'
'.editor':
'ctrl-t': 'tree-view:toggle'
Now it won't matter whether the editor or the Tree View is in focus, the toggle will be triggered nonetheless.
Final Thoughts
Another bit of advice when messing around with keybindings is to utilize the Keybinding Resolver. You can open this with cmd-.
. If you do this and try pressing ctrl-t
you will notice the keybinding that you have added shows up (highlighted in green). You will also notice that your keybinding is inhibiting another keybinding, editor:transpose
. Consider using a different keybinding.
The beauty of Atom is its customizability, just make sure you know the tradeoffs of your customizations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With