Disable default keybindings

#47

This works for me:

On keymap.cson (user keymap):

'.platform-win32 .editor':
  'ctrl-alt-q': 'unset!'
  'ctrl-alt-w': 'unset!' 

The catch here is the ‘unset!’ value to disable the keybinding

1 Like

Shortcut for folding code
#48

To make this work for me, I had to use 'unset!' on the other side of key-value pair. Eg to remove the default binding of ctrl-shift-S from “Save As…” and then map ctrl-shift-S to “Save All”, this worked for me:

'.workspace .editor:not(.mini), .workspace':
  'ctrl-shift-S': 'window:save-all'

'body':
  # Without this, ctrl-shift-S triggers "Save As..."
  'unset!': 'core:save-as'
1 Like

#49

You don’t need both rules to override Ctrl+Shift+S. You could just use:

'body':
  'ctrl-shift-s': 'window:save-all'
0 Likes

#50

:white_check_mark: I wanted to disable the cmd-up/down shortcut so I added the following to my key binding file:

'body':
  'cmd-up': null
  'shift-cmd-up': null
  'cmd-down': null
  'shift-cmd-down': null

'body .native-key-bindings':
  'cmd-up': null
  'cmd-down': null


'body .native-key-bindings':
  'shift-cmd-up': null
  'shift-cmd-down': null

:grinning:

It seems to be working for now.

0 Likes

#51

Agree with lukasoppermann about the override. I tried to override cmd-b cmd-r to what I usually use to run applications, didn’t work very well :frowning:

0 Likes

#52

I’m having the same issue and I don’t know how to solve it.

I used cmd+shift+e for HTML encoding, but Emmet uses it for expanding abbreviation.

If I use unset! it disables the shortcut completely.
'cmd-shift-e': 'unset!'

If I don’t, Emmet takes precedence over Atom commands.

If I leave the second field empty, nothing happens.
'cmd-shift-e': ''

I don’t want to edit Emmet package since I will have to do that every time I update Emmet.

There should be a way of disabling a keymap on the package config. Even better, if a new package is installed and it conflicts with other keymaps the user should be notified and those conflicting keymaps automatically disabled.

0 Likes

#53

If you use the same selector that Emmet uses for its keybinding and then change the command, it will work. From the Emmet package:

'.platform-darwin atom-text-editor:not([mini])':
  'cmd-shift-e': 'emmet:expand-abbreviation'

So if you put the following in your keymap.cson:

'.platform-darwin atom-text-editor:not([mini])':
  'cmd-shift-e': '[your desired command goes here]'

That should override it with no problem.

2 Likes

#54

Hey @leedohm thanks. It works!

I really don’t understand the logic of those selectors. I thought those were to scope the commands to a certain package… how come I can edit an .atom-text-editor command into .platform-darwin atom-text-editor:not([mini]) ? Doesn’t that make those selectors pointless?

0 Likes

#55

Commands are actually independent of packages. atom-text-editor here is a css selector and nothing more.

0 Likes

#56

Keybindings are mapped using CSS selectors. So if I only want a keybinding to work on a certain type of text editor or I only want a keybinding to work on OS X (i.e. platform-darwin), I can just change the selector.

0 Likes

#57

I came across a similar problem.
As a beginner in atom I want to mention a few more details that helped me solve the problem
that don’t seem obvious.

The configuration in keymap.cson overrides any default configuration so if
you unset a binding there the respective shortcut will do nothing.

To access that file you can first open settings with ctrl+, and then find a link to it in Keybindings.

In case your command binding is overridden by some other command, first
use the search field in Keybindings tab, where you can search both keystrokes, commands and packages.
After you find which commands you want to change and their keybindings
you need to add some lines at the end of keymap.cson in this format

'atom-text-editor':
  '<keybinding1>': '<command1>'
  '<keybinding2>': '<command2>' 

In any case information in keymap.cson can help further.

0 Likes

#58

This worked like a charm!

0 Likes

#59

Thank you. Now I am able to type the pipe character again (alt-h on Icelandic keymap on macOS)

0 Likes

#60

There seems to be a great variety of suggestions, none of which quite worked for me to override ctrl-tab. I don’t like the behaviour of switching to recently used tabs; I prefer to use them in visible order as per pane:show-next-item. My successful config is:

'body':
  'ctrl-tab': 'unset!'
  'ctrl-shift-tab': 'unset!'
'body:not([override-impossible])':
  'ctrl-tab': 'pane:show-next-item'
  'ctrl-shift-tab': 'pane:show-previous-item'

Thereby removing the existing keybindings from body and adding new keybindings that are ostensibly also in body. The choice of :not([override-impossible]) is an arbitrary one that matches as a css selector for body but with higher precedence (and without duplicate keys).

Hope this override pattern helps others.

2 Likes

#61

The recommended solution is listed in the FAQ:

1 Like

#62

Thanks @leedohm, I missed the FAQ, I should have done more searching. Now I get what the ^ctrl bindings are.

2 Likes

#63

Today I’ve downloaded atom after formatting my machine (Atom 1.13.0 on Windows 7 64-bit), and when adding my keymap.cson file I got the message:

Failed to load C:\Users\Stavo\.atom\keymap.cson
Duplicate key 'ctrl-tab'

keymap.cson

'body':
	'alt-shift-down':'editor:add-selection-below'
	'alt-shift-up':'editor:add-selection-above'
	'ctrl-tab':'unset!'
	'ctrl-shift-tab':'unset!'
	'ctrl-tab ^ctrl':'unset!'
	'ctrl-shift-tab ^ctrl':'unset!'
	'ctrl-tab':'pane:show-next-item'
	'ctrl-shift-tab':'pane:show-previous-item'

Did the way to do this change?

0 Likes

#64

The Atom FAQ has the canonical reference for how to do what it looks like you’re attempting to do:

0 Likes

#65

After removing the lines:

'ctrl-tab':'unset!'
'ctrl-shift-tab':'unset!'

Like in the FAQ, it no longer shows the error, but it shows that the key is used multiple times in the key resolver

Should I worry the other is showing, or only the line highlighted in green is used?

0 Likes

#66

Only the green highlighted one is used.

1 Like