1

I have this in my keymap.cson file:

'body':
  'ctrl-alt-left': 'editor:select-to-first-character-of-line'

But it doesn't work (there is no effect).

The following keymaps do work:

'body':
  'ctrl-alt-a': 'editor:move-to-beginning-of-line'
  'ctrl-alt-e': 'editor:move-to-end-of-line'
  'ctrl-alt-shift-s': 'editor:select-to-first-character-of-line'
  'ctrl-alt-shift-w': 'editor:select-to-end-of-line'

But I would like to be able to use the arrow keys.

max pleaner
  • 23,403
  • 8
  • 50
  • 99

1 Answers1

2

I'm not sure where you got the body selector from. You should use atom-text-editor for maps like this, as in the examples in the default keymap.cson in your .atom folder. This should do what you want:

'atom-text-editor':
  'ctrl-alt-left': 'editor:move-to-beginning-of-line'
  'ctrl-alt-right': 'editor:move-to-end-of-line'
  'ctrl-alt-shift-left': 'editor:select-to-first-character-of-line'
  'ctrl-alt-shift-right': 'editor:select-to-end-of-line'

When debugging issues like this, you must also keep a couple of other things in mind.

First, the meaning of alt varies by platform. On macOS, it means the Option key. On Windows or Linux, I believe it means the key labeled Alt, but your keyboard may be a bit different (especially non-US layouts).

Second, if a higher layer of the system (the OS itself, i.e. the window manager) is capturing a key combination, then it will never reach Atom at all. You can detect this situation using the Key Binding Resolver. You can activate it using Cmd. on macOS. I am not sure about other platforms, but usually Cmd on macOS maps to Ctrl on Windows and Linux, so I would suggest Ctrl..

While the Key Binding resolver is active, any keys or key combinations you press are listed in the resolver, along with the action (if any) within Atom that is taken. You can use this to determine what Atom thinks a given key is, and you can also use it to detect whether a given key combination is not reaching Atom in the first place.

Dan Lowe
  • 37,115
  • 15
  • 104
  • 98
  • i appreciate your advice but like I said in the question I'm getting the same effect as `ctrl-left`, which i should have specified is moving left _by word_. It doesn't seem my keymap.cson, opened via `ctrl-shift-p => 'open your keymap'`, is working at all. I've saved and rebooted Atom as well. – max pleaner Jan 19 '17 at 18:55
  • See the updated question. I realized alt-left actually has builtin functionality different than ctrl-left which I want to preserve, so I'm trying a different arrow key combination. But it's not working either. It only seems to work if I use alphabetical keys instead of arrows. – max pleaner Jan 19 '17 at 19:26
  • It's the same thing. Even with `'atom-text-editor'` it only works with `ctrl-alt-a`, not `ctrl-alt-left` – max pleaner Jan 19 '17 at 19:45
  • Actually, it does work with `alt-left`, `ctrl-left`, etc. just not `ctrl-alt-left` for some reason. Which now that I think about it isn't a bad thing, because I use that for window switching anyway. – max pleaner Jan 19 '17 at 19:46
  • @maxple What OS are you on? And what key on your keyboard do you assume is `alt`? That key varies by platform (for instance on Mac it means `Option`). – Dan Lowe Jan 19 '17 at 19:46
  • @maxple Well it is also possible a higher layer is capturing the key combination before it reaches Atom. For instance, on my Mac, I cannot remap `ctrl-left` or `ctrl-right`, as the OS itself catches those before Atom even sees them. You may be experiencing something similar. – Dan Lowe Jan 19 '17 at 19:47
  • Well, considering the combo works with `alt-left` I figure the alt key is registering ok. I'm on Linux (I know it's not atom's home base) on a small HP windows keyboard. – max pleaner Jan 19 '17 at 19:48
  • @maxple You can turn on the Key Binding Resolver and see what combos are actually being seen by Atom. I believe an earlier edit of your question had a screenshot with that tool, so I assume you know how to activate it. Then you at least know what key combo Atom believes you are using, and which ones may not ever reach Atom. – Dan Lowe Jan 19 '17 at 19:49
  • You're right. Certain combos like control-alt-arrow are not even being registered by the resolve. – max pleaner Jan 19 '17 at 19:52
  • @maxple I've updated my answer with some notes on the Key Binding Resolver since we discussed in comments. – Dan Lowe Jan 19 '17 at 19:59