conditional keybindings (alternate screen buffer)
Description of the new feature/enhancement
there are situations where it would be useful to conditionally bind/unbind keys: e.g. the default find { "command": "find", "keys": "ctrl+shift+f" } behavior to search all output text is usually undesirable in editors like emacs.
similarly, other common commands like copying and pane management* can be inappropriate in certain situations, where one would prefer those keys to be unbound from the terminal actions.
(*suspects this one may be up to personal preference/workflow)
the reverse situation also exists: a common hack is to have the terminal remap certain modifier sequences to sequences that can be interpreted safely. consider the mapping:
{ "command": { "action": "sendInput", "input": "\u001b[27;5;73~" }, "keys": "ctrl+i" }
where the processed sequence can be understood by emacs and friends for keybinding.
so a proposal is to be able to designate conditional activation for keybindings.
motivating failed workaround
a while back, tried having an settings-emacs.json and a settings-normal.json that on activate/suspend get copied to settings.json. this... technically works... but is bad for a number of reasons, obviously. there's a lot of redundancy, every change has to be made twice, settings editing can't be done from the gui (it'll be overwritten), the swap condition itself has many flaws and inevitably breaks with multiple windows/tabs/panes...Proposed technical implementation details (optional)
for this use case, an acceptable solution is to just have keybinding groups and/or properties that can respect alt buffer state. but maybe a more generic solution is useful? to be able to listen for arbitrary control sequences. 'enable these commands after CSI 104;93m and disable after CSI 0m.' ...hopefully there are no situations where one needs hacks like that. regardless, it would be very powerful.
can't remember if per-profile bindings are already possible. ignoring the overkill option, it would be good to at least detect profile and altbuf state.
maybe duplicate of but proposes alternate/more general solution to: #9045 ("support alt buffer correctly and pass keys through")
sort of related: #9534 #7006 #5857
This isn't an entirely bad idea. I've had a mind in the past to have something like named sets of keybindings, and then allow different profiles to specify different keybindings by name. Wouldn't be insane to also use that mechanism for a profile's altBufferKeybindings as well.
Thanks for the idea!
I really like this idea! It's also another vote for contextual key bindings, which we've been dancing around for a little bit. :smile:
For reference, VS Code has contextual keybindings with when clauses. In 1.61 they added support for checking if in the alt buffer. I dunno if we're gonna use when clauses ourselves, but I figured I'd reference the prior art here.
First step is to make keybindings per profile instead of global, that would already be a big win.