Keyboard Mapping question?

I’m looking to change the the key binding used for line sorting from F5 to F15.

I’ve changed config.json to:

“*”:
core:
packagesWithKeymapsDisabled: [
“sort-lines”
]
telemetryConsent: “no”
themes: [
“one-light-ui”
“one-light-syntax”
]
editor:
softWrap: true
“exception-reporting”:
userId: “bdd4578f-b778-484e-9746-fd76b4a2c3a9”
“one-light-ui”:
fontSize: 13
welcome:
showOnStartup: false

and added the following to the top of keymap.cson:

‘atom-text-editor:not([mini])’:
‘f15’: ‘sort-lines:sort’# Your keymap

But no matter what I do the F15 is being ignored. Any tips on what I’m missing would be appreciated.

Anybody at all?

Anyone at all guys? I’d love to get this resolved …

Can you use code fences (three backticks above and three backticks below your code) to format your config files?

Like this:

```cson
core:
  key: value
```

That would make it easier to see the spaces/indentation. Looks like this when rendered:

core:
  key: value

If it allowed me to edit the post (now that I know that) I would :slight_smile:

Any ideas thoughts on how to fix the issue?

If you can’t edit it, add it in a new comment below.

Okay here you go :slight_smile: Does that help?

I’m looking to change the the key binding used for line sorting from F5 to F15.

I’ve changed config.json to:

“*”:
core:
packagesWithKeymapsDisabled: [
“sort-lines”
]
telemetryConsent: “no”
themes: [
“one-light-ui”
“one-light-syntax”
]
editor:
softWrap: true
“exception-reporting”:
userId: “bdd4578f-b778-484e-9746-fd76b4a2c3a9”
“one-light-ui”:
fontSize: 13
welcome:
showOnStartup: false

and added the following to the top of keymap.cson:

‘atom-text-editor:not([mini])’:
‘f15’: ‘sort-lines:sort’# Your keymap

But no matter what I do the F15 is being ignored. Any tips on what I’m missing would be appreciated.

The quote characters are incorrect; they should be ". The indentation is also important; CSON is indentation sensitive.

All the examples here show the ’ character being used?

Also looking at the various tutorials out there then adding this to the keymap file should work:

'atom-text-editor:not([mini])':
  'key f15': 'sort-lines:sort'

The code block look fine, just remove the key part. You can use the keybinding resolver (ctrl-.) to check what key names are.

The examples you reference show ' being used, not . On this forum text is markdown, which is convenient for nice looking comments but mangles code. This is why we asked for your verbatim content to be in code blocks; that prevents things like ' being turned into and indentation being lost, which are the most common sources of error in the config files. Regarding the use of ' though, either ' or " is fine so long as you end with the one you started with.

Understood. I now have whatI had originally:

'atom-text-editor:not([mini])':
  'f15': 'sort-lines:sort'
#
# Atom keymaps work similarly 

and it still fails. The config editor shows it looks to be okay as well:


I’m completely mistified…

Check the command palette (ctrl-shift-p) for Sort lines: sort or similar. It’s possible you don’t have a command with that name installed.

( ctrl-shift-p ) doesn’t do anything for me on a Mac alas.

The sort lines package is installed and runs if I access it via the menu. The menu even shows the keybinding is in place. It just will not run from the key.

image

On mac just replace all ctrl with cmd and it will generally be the intended binding. Note that the control palette is a common way of interacting with commands, especially ones not common enough to deserve a keybinding, so that’s a good shortcut to know. Almost all keyboard shortcuts run commands that are listed in the control palette.

Try adding the following to your keybindings file and press f12. Make sure it is the only contents of the file; duplicate keys (the string before the :) will be ignored (which is another possibility if what you have shown us isn’t your whole keymaps file).

'atom-text-editor:not([mini])':
  'f12': 'editor:log-cursor-scope'

Okay I changed the keymap to only what you recommended and I got back:
Screenshot 2020-10-06 at 10.45.27
Which looks right to me. I then loaded back the full keymap file:

'atom-text-editor:not([mini])':
  'f12': 'editor:log-cursor-scope'
  'f15': 'sort-lines:sort'
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts. Unlike style sheets however,
# each selector can only be declared once.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
#
# 'atom-text-editor':
#   'enter': 'editor:newline'
#
# 'atom-workspace':
#   'ctrl-shift-p': 'core:move-up'
#   'ctrl-p': 'core:move-down'
#
# You can find more information about keymaps in these guides:
# * http://flight-manual.atom.io/using-atom/sections/basic-customization/#customizing-keybindings
# * http://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/
#
# If you're having trouble with your keybindings not working, try the
# Keybinding Resolver: `Cmd+.` on macOS and `Ctrl+.` on other platforms. See the
# Debugging Guide for more information:
# * http://flight-manual.atom.io/hacking-atom/sections/debugging/#check-the-keybindings
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#configuring-with-cson

and again your binding worked. Alas the F15 still fails to trigger the sorting package… This is driving me slowly nuts.
All I want to achieve is hitting the F15 key will sort the selected lines alphabetically… Maybe I should give up and just use the menu…

Try opening the keybinding resolver (cmd-. on mac, not the keybindings tab in settings. Can also be found by searching in the command palette) to see what it sees your f15 key as, as well as what it is trying to execute when you press it.

Problem solved. It was not an Atom issue at all. I suddenly had a thought that what could stop a keyboard shortcut from being seen - if it was used elsewhere! So I went into the keyboard shortcut system on the Mac…
And there it was. Unchecking the ‘Increase display brightness’ option of the display fixed it :slight_smile:

I’d not known about that keyboard mapping as I use a stand alone monitor with my Mac Mini so those function keys do nothing for me.
Thanks for the assistance guys!
image

1 Like