How to replace a keymap binding


I would like to change the key binding for ctrl-j, so I add a mapping to the keymap

‘ctrl-j’: ‘core:move-left’

The problem is the previous keybind is still in effect so the previous one takes precedence. The Atom documentation says you can use ‘ctrl-j’: ‘unset!’. So I tried

‘ctrl-j’: ‘unset!’

‘ctrl-j’: ‘core:move-left’


‘ctrl-j’: ‘unset!’

‘ctrl-j’: ‘core:move-left’


‘ctrl-j’: ‘unset!’
‘ctrl-j’: ‘core:move-left’

None of them worked. So what is the proper procedure for clearing out any previous key mapping and replacing it with a new one?


You can open the keybinding resolver (ctrl+.) and then press the keybinding to see which scope it is bound to. Then you can unset! that key combo for that specific scope.


In addition to @olmokramer’s advice, you can use the Keybinding tab in the Settings View (Cmd+, on OS X and Ctrl+, on Linux/Windows) to look up the offending key binding. Once there, you can use the clipboard icon to the left to copy the definition for pasting directly into your keymap.cson.


So if the keybinding is:

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-j': 'editor:join-lines'

I would add the following to my local key binding file:

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-j': 'unset!'
  'ctrl-j': "custom:my-command'

This still exhibits the same issue - both commands are run instead of just one. The keybinding resolver indicates there are now three bindings on this keystroke: ‘editor:join-lines’, ‘custom:my-command’, and ‘unset!’, with ‘editor:join-lines’ and ‘unset!’ in the same scope of ‘atom-workspace atom-text-editor:not([mini])’


If you can show a screenshot of the Keybinding Resolver, one of the commands should be a different color. That is the only one that should be executed.


They are all the same color - gray.


Looks like none of them are being executed? I’ll have to take a look at this a bit when I get home.


It looks like the “editor:join-lines” is the only one being executed. If I change the third one to “core:move-up”, the cursor does not move up - the two lines are just joined.

Appreciate your help so far.


So here’s what I ended up doing that worked:

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-j': 'core:move-left'
  'ctrl-j': 'core:move-left'

Instead of unset!, I just went ahead and mapped core:move-left to Ctrl+J in the atom-workspace atom-text-editor:not([mini]) selector. And then to ensure that Ctrl+J worked in mini text editors too, I mapped general atom-text-editor as well.

Let me know if that helps :grinning:

What's wrong with my ctrl-[hjkl] and ctrl-\ keybindings?

Not sure why the “unset!” doesn’t work like documented, but I’ll take your solution because it seems to work.


There’s an Issue open on this here:


Thanks!! PS. It works, but it requires to restart atom, not just saving the keymap.cson file as in other cases.


There is a package called atom-save-all that after it is installed, all modified panels will save when ctrl-s is pressed.


I’m struggling with this – why would a package override my keymap with identical CSS selectors? This is on atom 1.6.0.

I thought that my keymap would take precedence in this case. Sorry about the dim colors.


It’s hard to answer that without knowing exactly what you have in your keymap.cson.


Sorry, Here is the keymap.cson. I tried to match the selector in the encoding-selector module:

'.platform-linux atom-text-editor':
    'alt-u': 'git-diff-details:undo'

(this is the entirety of my keymap.cson).


It looks like it should win, but I also don’t know much about the git-diff-details package. Does git-diff-details use an atom-text-editor element? Perhaps the command you’re trying to map doesn’t apply in that context?


You’re right. I was testing in the tab that had keymap.cson open. Not a git repo, and I guess the git-diff-details package didn’t apply.

It works perfectly in a git repo. I was misunderstanding the key binding resolver.

Thanks for the help!


Great! I’m glad this is working for you now :tada: :boom:


Does overriding with atom-workspace work anymore?

I can’t get this keymap to work:

It always resolves to regular tab.