zellij icon indicating copy to clipboard operation
zellij copied to clipboard

Ignore keybinding based on a condition

Open tqwewe opened this issue 1 year ago • 2 comments

Would it be possible to disable specific keybindings based on the name of the current program running in a panel?

While using some programs such as nvim, I have a keybinding Ctrl-s to save the current buffer. However Zellij intercepts this keybinding for scrollback keybindings. But when using nvim (or some other terminal UI), I wouldn't really want to edit the scrollback in my default editor.

tqwewe avatar Mar 25 '24 07:03 tqwewe

Hey, I found Ctrl+G keybind which locks the interface until it's pressed again, which is a good workaround for this If Ctrl+G is also used then just rebind it in Zellij to something else

rehhouari avatar Mar 29 '24 09:03 rehhouari

If you use Zsh you can use this which I just put together to automatically lock on certain commands:

https://gist.github.com/rehhouari/a287b22b468fb295273b782297142bed

# Define an array of commands that will lock Zellij when ran
locked_commands=("micro" "nano")

# Store the last command we ran, this is to be used in precmd()
local command=''

# Run before a command is executed
function preexec() {
	# Extract the command from the input string
	local cmd=${1%% *}
	command=$cmd
	if [[ " ${locked_commands[@]} " =~ " $cmd " ]]; then
		zellij ac switch-mode locked
	fi
}

# Run after a command exits
function precmd() {
	if [[ " ${locked_commands[@]} " =~ " $command " ]]; then
		zellij ac switch-mode normal
	fi
}

put it in ~/.zshrc or ~/.oh-my-zsh/custom/zellij-lock.zsh if you use Oh My Zsh

rehhouari avatar Mar 29 '24 12:03 rehhouari