Application dependent keybindings #6184
Replies: 3 comments 2 replies
-
not sure if it is better, but there are different tradeoffs if you use the update-status event to determine the foreground application, then use https://wezfurlong.org/wezterm/config/lua/window/set_config_overrides.html to override the keybindings |
Beta Was this translation helpful? Give feedback.
-
Note that you can always write a Lua function that returns a keybind, so you'd only have a single function call for each keybind you want to pass through. Something like: (not tested) local function passthrough_keybind_for(process_name, key_info)
return {
key = key_info.key,
mods = key_info.mods,
action = wezterm.action_callback(function(window, pane)
local fg_process_name = pane:get_foreground_process_name()
if fg_process_name == process_name then
window:perform_action(wezterm.action.SendKey(key_info), pane)
end
end),
}
end
-- ...
keys = {
passthrough_keybind_for("nvim", { key = "K", mods = "CTRL" }),
-- ...
} |
Beta Was this translation helpful? Give feedback.
-
The issue I ran into using that approach was that keybinds were swallowed in other apps. So, for instance, if another app (other than nvim) had a CTRL+K keybind then nothing would actually happen because wezterm was just swallowing it. Here's an updated version that passing through keypresses to apps where you don't want to handle it. My setup below is a little different in that I want keybinds that only work in the shell prompt, otherwise, just pass it through. But you can update it for nvim. There's got to be an easier way...
|
Beta Was this translation helpful? Give feedback.
-
What Operating System(s) are you running on?
Linux X11
Which Wayland compositor or X11 Window manager(s) are you using?
i3
WezTerm version
wezterm 20240915-153243-2d0c5cdd
Ask your question!
I want to forward certain keystrokes as escape sequences ONLY when nvim is running as foreground application behind the tty. Is this somehow possible? I know that there's the approach with
but this is so verbose and cumbersome if you have many keybindings! Is there a better approach?
Beta Was this translation helpful? Give feedback.
All reactions