zellij: Unable to send ctrl-g without rebinding in the config (one liner)

Description

With the default config I can’t seem to find a way to send Ctrl-g to any programs I run in zellij because it’s the key to both enter and exist the locked mode.

You can send any other key that’s already used by the default config by entering the locked mode with Ctrl-g, then hitting the key you want to send, and leaving locked mode with Ctrl-g again, but that doesn’t work for Ctrl-g itself.

Information

  • zellij 0.6.0
  • Arch Linux 5.11.16-zen1-1-zen

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 9
  • Comments: 27 (11 by maintainers)

Most upvoted comments

I noticed that I’m unable to send Ctrl-g when I tried to use it in vim to print the current file name.

Some solution that come to mind are these:

  • Change the keybind to leave locked mode to esc. You can already send esc in normal mode, though you might want to send esc in locked mode without wanting to leave locked mode.

  • If Ctrl-g is the first key entered in locked mode: send Ctrl-g and leave locked mode. This behavior is similar to Ctrl-b Ctrl-b with the default tmux config, but this prevents users from leaving locked mode without sending anything if they entered it by accident.

  • Add a keybind that sends only the next character, like Ctrl-v in vim’s insert mode.

* Add a keybind that sends only the next character, like `Ctrl-v` in vim's insert mode.

This is my favorite solution. I would also:

  1. Make this keybind Ctrl-g and change the current behaviour to happen with Ctrl-G (uppercase G). This way we can make just a minor change to the interface by changing it to <g/G> LOCK
  2. Change the -- INTERFACE LOCKED -- indication for the lowercase variant (the temporary one) to -- INTERFACE TEMPORARILY LOCKED -- to make it clear to the user.

What do you think?

Friends, I want to stress again: we can bind/unbind/rebind any key in the config by changing one line. I changed the issue title accordingly to try and make it as clear as possible. I don’t know how to make this clearer. 😃 More info here: https://zellij.dev/documentation/keybindings.html

While I can empathize with wanting things to work just the way you like them out of the box - and I do agree we can do more in that area and indeed plan to - it takes less effort to adjust this in the config than it took me to write this comment.

has this issue been addressed? I think this is the only thing that blocks most of user from using zellij as a main terminal multiplexer. and so do i.

as it may affect nano, emacs, any kind of CUI applications.

Completely agree. Many apps use control-g. In emacs it is even the most important shortcut since this might be the only key that saves you from an emacs hang up.

This would improve on a feature that tmux has that Zellij doesn’t, the ability to pass through the prefix key.

Which in this case is an improvement over Tmux’s solution of a separate keybind just to pass through the prefix keybind.

So I believe the solution is simpler than it seems at first, at least when using the newer “non-colliding” preset.

You just have to tweak the existing binding that maps Ctrl g to go back into locked mode to make it send Ctrl g before changing back to locked. For Ctrl g you just have to add Write 7; in front of the existing binding behavior. It almost feels too easy…

Here’s the block where I made the change in the default “non-colliding” config file on a fresh install:

    shared_except "locked" "renametab" "renamepane" {
        bind "Ctrl g" { Write 7; SwitchToMode "locked"; }
        bind "Ctrl q" { Quit; }
    }

This appears to work just like the usual approach in tmux where you type the prefix twice to send the prefix to the application. Between the non-colliding preset and this easy hack I finally feel like I can move on from tmux.

@imsnif I very nearly put off switching from tmux again over this, because at first glance for a beginner it looks like there is no real support for this behavior, even after doing a decent amount of searching (and I also tried asking a few LLMs). In this thread it really looks like you are saying to just rebind the prefix key, but people are asking how to send that prefix key to the underlying pane in the rare situations where they may need to do so.

This simple config tweak might be worth putting in the docs so people can easily see how to send their chosen prefix. For me in vim I do occasionally use Ctrl g to see a file’s path when its window is too narrow to fit in the mode line.

FWIW I think this bug should be re-opened and something like https://github.com/zellij-org/zellij/issues/418#issuecomment-830019834 implemented. It was rather confusing coming across this as a new user and other multiplexers having some solution to this.

That is definitely an improvement over it having to be ctrl+g. However, whichever key you choose, you won’t be able to send that one to internal programs.

Here is my hacking to send a real Alt-g to the terminal (I use alt-g instead of ctrl-g for the lock mode switching key):

    locked {
        bind "Alt g" { SwitchToMode "Normal"; }
    }

    normal {
        bind "Alt g" { SwitchToMode "Locked"; }
    }

    shared_except "locked" {
        bind "Ctrl a" { SwitchToMode "Tmux"; }
        bind "Alt p" { SwitchToMode "Pane"; }
        bind "Alt r" { SwitchToMode "Resize"; }
        bind "Alt s" { SwitchToMode "Scroll"; }
        bind "Alt o" { SwitchToMode "Session"; }
        bind "Alt t" { SwitchToMode "Tab"; }
        bind "Alt m" { SwitchToMode "Move"; }
        bind "Alt g" { Write 27 7015; SwitchToMode "Normal"; } // send a real Alt+g to the terminal
    }

So with this setting, in any mode (like Pane, Resize, Scroll, or whatever mode), press Alt-g to send a real Alt-g to the terminal, and in normla mode, press Alt-g to enter the lock mode.

That is definitely an improvement over it having to be ctrl+g. However, whichever key you choose, you won’t be able to send that one to internal programs.

I think this is a very old issue and can be closed.

@vyalovvldmr - you’ll need to explicitly unbind “Ctrl g” in all modes (and hopefully bind it to something else). You can look into overriding keys here if you like: https://zellij.dev/documentation/keybindings-binding.html#overriding-keys

I just came accross the same issue: “Ctrl-g” is used to open the help screen in the nano editor. Instead of a help screen you get a lock in the terminal. “Ctrl-r” is also a nano command.

We’re definitely not alone in having this problem, and there are a number of different approaches:

  • Choosing an obscure keybind (as we’re proposing?)
  • Having a command to do it, a la telnet
  • Using some key repetition, a la screen

The screen one will mean that my default screen bindings require me to Ctrl+g g g in order to send Ctrl+g to the shell if I run zellij under screen for persistence 😄

I also think that this is the best solution.