Sublime Forum

Key Unbinding

#1

Is there a way to cleanly unbind a command from a package?

I ran into this problem with Emacs Pro Essentials and SublimeLinter. In the Emacs package ctrl-k is setup to a command that kills from the point to the end of the line, per Emacs behavior. However ctrl-k was also chosen to be used by SublimeLinter authors to precede certain commands like ctrl-k p in a keystroke pattern keybinding (as opposed to a pure chording keybind.)

I did some poking around and it seems like a popular choice for unbinding a key is to redefine it as a “noop” command. However this is not a particularly clean unbinding. All it does is prevent the keybind from executing. It does not instruct the keybind system in ST to not pay attention to the keybind. In this particular case because the keybinds were keystroke patterns, ST will wait to find out if there’s a following keystroke after the initiator. As a result, ctrl-k in Emacs mode was still operating really strangely.

The only solution I had was to comment out all the keybinds in SublimeLinter and restart. Fortunately that package is one that installed not as a .sublime-package but rather in a directory. (Honestly I didn’t even know there was an option to not use the package file format through Package Control, but that’s a different topic.)

Is there a better way to eliminate keybinds?

0 Likes

#2

The proper way would be an override file (with PackageResourceViewer).

0 Likes

#3

I’m interpreting the “override file” as my own User keybinding preferences. However again, ST still listens for the keybind once it’s been declared, which in the case of a multi keystroke command causes the above failure with overlapping keystrokes.

I suppose in that case, either using PackageResourceViewer to edit and comment out the undesired keybinds is really the only way to make ST ignore certain sequences.

0 Likes

#4

Generally for the term override, community members are talking about the ability of Sublime Text 3 to allow you to create a custom file that is used in place of a file in a .sublime-package. See the last section of http://www.sublimetext.com/docs/3/packages.html for more info.

Effectively this allows you to prevent the author’s original key bindings, menu entries, command palette entries, etc from ever being loaded in the first place.

3 Likes

#5

If you open a package resource with PackageResourceViewer for a package that is installed as a sublime-package file, make changes and then save it, you’re creating a package override (which is what @FichteFoll was saying above). What you’d do is save the file back with any offending content removed, commented out, etc.

What you’re doing is creating a local directory in the Packages folder named after the package that contains the file that you edited and storing your modified version of the file there. In use Sublime will ignore the similarly named file inside the sublime-package file and use your override file instead.

This is an “end run” on just modifying the package file contents, because if you do that when the package gets updated your changes get lost. This is true even for packages that are not installed as sublime-package files, which is why it’s generally preferred to have your package installed that way if you don’t need to be unpacked.

When you create an override like this, Sublime will use your version of the file forever, even if the package is updated. This means that if there are any changes made by the package author, your changes will mask them. You don’t get notified by Sublime when this is happening.

Detecting when you have overrides, how they’re different from the underlying file, and when the underlying file is updated is the core of my OverrideAudit package.

6 Likes

#6

Ahh okay. I believed that if I edited with PackageResourceViewer (I have it installed but hadn’t actually used it just yet) that I was saving back to the original. I didn’t realize that I was created a local edited copy. I’ll have to do that for SublimeLinter then because it could theoretically get updated.

0 Likes