Hotkey Contexts

Add Context to Hotkeys

Currently, if a hotkey has a conflict there’s a good chance it will not work at all, despite there being situations where it’s fairly tame to have a hotkey do a similar action but in different situations. The example that inspired me to write this was trying to map Alt+Arrow to moving table rows/columns around using the new built-in table editor, only to find that it conflicted with the shortcut to move lines up and down, which I had already assigned. These two features ostensibly do the same thing in raw markdown, but it’s fairly intuitive to separate when I might want one or the other. In the Live Preview editor, elemental actions like reorganizing a table or list (c.f. Outliner plugin) are more likely what the user is trying to do over the raw action of line manipulation. This gets me thinking that adding contexts to assigned hotkeys might be a useful way to solve a lot of conflicts.

The gold standard for what contextual shortcuts involves is something like VSCode, where the many boolean context identifiers associated with the current focus can be granularly adjusted and applied to commands by users, with support for boolean and set-like logic. I assume this would be a momentous undertaking to implement in Obsidian, so for now, I wonder about the implementation of the simple analog of just an Editor Mode context.

If I could assign shortcuts to specifically Live Preview, Source, (and even Reading) mode, I could more efficiently utilize shortcuts where it’s more obvious to me what sort of action I’m looking for. I could use Move line only in Source mode, and Move row, etc. only in Live Preview. And maybe, in Reading Mode, the same shortcut could instead move pane focus, scroll the view, etc.

I envision adding a datum to each assignment that specifies what Mode it’s associated with and possibly adding color based on mode. It wouldn’t have to be a multi-select modal, instead users would select only one context for a given assignment, and only if two assignments use the same hotkey in the same mode would a conflict error arise.

Looking to the future, I could see hotkey contexts extend to things like “am I in a table environment?” or “am I in a codeblock?” (with language-aware context enabling a language-aware Toggle Comment command, for example), but of course happy to Keep It Skeptically Simple.


I’ve also come up against this problem and it would definitely be helpful! Another example is when using excalidraw, I can’t use existing hot keys for excalidraw commands despite them having no other possible view to act on.