Overriding core keybindings?


#1

I have problem with accents, I’m on win 8.

Let’s take ’ as an example:

‘ś’ maps to ctrl-alt-s (this is right alt), which is bound to spec suite toggle in core.
I tried to override it, but no luck. It writes the letter, but also toggles spec suite.

'body':
  'ctrl-alt-s': 'unset!'
  'ctrl-alt-s': 'native!'

'.editor':
  'ctrl-alt-s': 'unset!'
  'ctrl-alt-s': 'native!'

i can see in settings:

ctrl-alt-s application:run-all-specs Core body
ctrl-alt-s native! User body
ctrl-alt-s native! User .editor

it looks like I can’t unset core bindings…
With this override, Keybinding Resolver doesn’t show run-all-specs binding anymore, but freakin Spec Suite appears anyway.

Previously I’ve edited the win32.json file, but with new version I can’t.

By the way, it seems silly to map default core bindings to default accent button…


#2

I’m having the same problem on OSX 10.9.3. Even keystrokes I’m overriding are not disabling the core bindings and the core seem to take priority. I’ve just noticed this too—it seems to be a recent version that’s causing the issue.


#3

The same problem occurs on Windows 8.1. The “unset!” directive has no effect on the Specs Runner.


#4

Are you using duplicate sections in the keybinding.cson?


#5

Hi there,
I was doing the same thing: overriding a bunch of default keybindings. Here’s the result:

Fail:

 'atom-text-editor':
 'cmd-enter': 'editor:duplicate-lines'

Using the latest selectors (e.g. ‘atom-text-editor’) may work sometimes, and the result is inconsistent. I restart my Atom and poof, it stopped working. Don’t know what causes this though.

Fail:

 '.editor':
 'cmd-enter': 'editor:duplicate-lines'

using ‘.editor’ works for some keybindings, but some will fail to override. The result is consistent though (always work or never works).

Success:
I use ‘.editor:not([mini])’ as my selector for all my keybindings; they all work consistently. keymap.cson looks like:

# useful keybindings and overrides
'.editor:not([mini])':
  # duplicate-lines
  'cmd-enter': 'editor:duplicate-lines'
  # delete-line
  "cmd-'": 'editor:delete-line'
  # go-to-line
  'cmd-l': 'go-to-line:toggle'
  # select-word
  'alt-shift-W': 'editor:select-word'
  # select-line
  'shift-cmd-l': 'editor:select-line'
  # fold-selection
  'alt-cmd-\\': 'editor:fold-selection'
  # go-to-matching-bracket
  'cmd-\\': 'bracket-matcher:go-to-matching-bracket'
  # select-inside-brackets
  'cmd-|': 'bracket-matcher:select-inside-brackets'
  # beautify: re-indent
  'cmd-{': 'atom-beautify:beautify-editor'
  'cmd-}': 'atom-beautify:beautify-editor'
  # markdown-preview
  'alt-/': 'markdown-preview:toggle'
  # term2 open console
  'ctrl-`': 'term2:open'
  'ctrl-[': 'term2:open-split-left'
  'ctrl-]': 'term2:open-split-right'
  # script run
  'shift-cmd-I': 'script:run-by-line-number'
  # git add-all-and-commit
  'shift-cmd-A': 'git-plus:add-all-and-commit'

Hope this helps.


#6

Nice! Thanks for that!
I could also only get my keybindings to work how I wanted by placing them under ".editor:not([mini])", e.g.:

".editor:not([mini])":
  "ctrl-a": "editor:move-to-first-character-of-line"
  "ctrl-e": "editor:move-to-end-of-screen-line"
  "ctrl-r": "find-and-replace:use-selection-as-find-pattern"
  "ctrl-shift-A": "core:select-all"

I wonder if this is expected behavior…?

EDIT: Okay I’d definitely like to figure this out, because I just noticed that Deprecation Cop doesn’t like the editor class.


#7

Have you tried using the Keybinding Resolver? (Cmd+. on OS X, Ctrl+. on other platforms) It will show you what keys Atom thinks you’re pressing and the command it executes because of them. For example, using @kengz example above for Cmd+Enter after correcting the indentation:

'atom-text-editor':
  'cmd-enter': 'editor:duplicate-lines'

This is the result I got:

So the key binding isn’t failing because of the use of the atom-text-editor selector, it is failing because it isn’t as specific (or more specific) as the built-in selector. When I change it to match:

'atom-workspace atom-text-editor:not([mini])':
  'cmd-enter': 'editor:duplicate-lines'

It works just fine: