Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to selectively disable key bindings? #6471

Open
imax9000 opened this issue Sep 3, 2024 · 6 comments
Open

How to selectively disable key bindings? #6471

imax9000 opened this issue Sep 3, 2024 · 6 comments

Comments

@imax9000
Copy link

imax9000 commented Sep 3, 2024

Problem description

I want to disable the following:

{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
	]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
	[
		{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
		{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
		{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
	]
},

How do I do that without patching Default.sublime-package (and having to repeat that on every update) and without removing the normal functionality of the Enter key (which "command":"noop" would do, IIUC)?

Preferred solution

🤷

Alternatives

🤷

Additional Information

No response

@jfcherng
Copy link

jfcherng commented Sep 3, 2024

I think there is no concept of "disabling" a keybinding in ST. All keybindings are piled up and there is no way to "remove" a single keybinding. People may say "another command gets preferred" is effectively "disabling the original keybinding" (i.e., the noop way you mentioned). However, they are all there.

@imax9000
Copy link
Author

imax9000 commented Sep 3, 2024

.config/sublime-text/Packages
├── Default
│   └── Default (Linux).sublime-keymap
└── User
    └── Preferences.sublime-settings

Okay, this seems to work, but I won't be seeing any changes done in the Default package unless I merge them manually.

@imax9000
Copy link
Author

imax9000 commented Sep 3, 2024

I think there is no concept of "disabling" a keybinding in ST. All keybindings are piled up and there is no way to "remove" a single keybinding. People may say "another command gets preferred" is effectively "disabling the original keybinding" (i.e., the noop way you mentioned). However, they are all there.

Ack, thanks. So there's no way to do it other than replacing the whole keymap.

@rchl
Copy link

rchl commented Sep 3, 2024

In this case this key binding depends on auto_indent preference being enabled. So disabling the preference will disable those key bindings. The potential issue with that is that there are also other key bindings that depend on auto_indent preference and you maybe would not want all of them to be disabled.

@imax9000
Copy link
Author

imax9000 commented Sep 3, 2024

In this case this key binding depends on auto_indent preference being enabled. So disabling the preference will disable those key bindings. The potential issue with that is that there are also other key bindings that depend on auto_indent preference and you maybe would not want all of them to be disabled.

Exactly.

@keith-hall
Copy link
Collaborator

I believe the canonical way is to just duplicate the binding into your user keybindings file and replace the command with noop - as all the contexts will be the same, no other keybindings will be lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants