zellij icon indicating copy to clipboard operation
zellij copied to clipboard

Feature(Config): Make Modes Configurable

Open a-kenji opened this issue 4 years ago • 5 comments

Defining new modes via the config file (and keybinds to switch to them)

Originally posted by @khs26 in https://github.com/zellij-org/zellij/issues/224#issuecomment-812881572

Would it be desirable, or even practical to let users create their own modes? How would that look like?

a-kenji avatar Apr 03 '21 18:04 a-kenji

I'm a definite +1 on this, this would give us alot more ability to allow different bindings, and allow those who use other multiplexers to move over to Zellij easily. It could also create a cottage industry of making configurations for Zellij.

SaintFenix avatar Apr 25 '21 16:04 SaintFenix

This! Custom modes is the one thing holding me back from using Zellij daily!

Aidan-Chelig avatar Apr 22 '22 00:04 Aidan-Chelig

here's my use case:

I want to be able to:

  • use modes and key sequences for everything you can do in Zellij (Vim style)
  • define keys sequences, ideally with built-in syntax, e.g. p with hjkl using e.g. bind "ph" {} / bind "pj" {} / bind "pk" {} / bind "pl" {} to e.g. open a pane in that direction
    • in a similar fashion to how you can do dw to delete a word in Vim
    • currently, in a hacky way, you can already define key sequences using modes, e.g. pane actions/sequences that start with p use the built-in pane mode that is entered with p by default. but this is not optimal for ease of use or readability, and we only have a couple of built-in modes.
      • the ability to have more modes, custom modes, can enable you to define more key sequences for other actions you can do in Zellij.
  • use the Lock mode of zellij as the "Insert" mode and only that mode to type text or use any shortcut for the program running inside Zellij and not worry about conflicts with Zellij's shortcuts.
    • this is similar to how Vimium, the browser extension, has an "Insert" mode that allows all input to pass through to the web page (except Esc).

here's my basic config.kdl:

// to override the default keybindings completely, set property "clear-defaults=true"
keybinds clear-defaults=true {
    shared {
        //bind "Esc" { SwitchToMode "Normal"; } //can't use it because vim uses it
        bind "Alt z" { SwitchToMode "Normal"; }
    }
    normal {
        // disable all keys
        bind "`" "1"    "2"    "3"    "4"    "5"    "6"    "7"    "8"    "9"    "0"    "-"  "="    "\\"  "Backspace" \
             "~" "!"    "@"    "#"    "$"    "%"    "^"    "&"    "*"    "("    ")"    "_"  "+"    "|" \
        "Tab" ";"    "q"    "w"    "f"    "p"    "b"    "'"    "l"    "u"    "y"    "j"    "]" \
        "Tab" ":"    "Q"    "W"    "F"    "P"    "B"    "\""    "L"    "U"    "Y"    "J"    "}" \
        "/"    "a"    "r"    "s"    "t"    "g"    "k"    "n"    "e"    "i"    "o"    "Enter" \
        "?"    "A"    "R"    "S"    "T"    "G"    "K"    "N"    "E"    "I"    "O" "Enter" \
        "z"    "x"    "c"    "v"    "d"    "["    "h"    "m"    ","    "." \
        "Z"    "X"    "C"    "V"    "D"    "{"    "H"    "M"    "<"    ">"  {}
        bind "Space" "Esc" {}
        bind "h" { MoveFocus "Left"; }
        bind "j" { MoveFocus "Down"; }
        bind "k" { MoveFocus "Up"; }
        bind "l" { MoveFocus "Right"; }
        bind "p" { SwitchToMode "Pane"; } // enter pane mode
    }
    locked {
    }
    pane {
        bind /*ph*/ "h" { NewPane "Left"; SwitchToMode "Normal"; MovePane "Left"; } 
        bind /*pj*/ "j" { NewPane "Down"; SwitchToMode "Normal"; } 
        bind /*pk*/ "k" { NewPane "Up"; SwitchToMode "Normal"; MovePane "Up"; } 
        bind /*pl*/ "l" { NewPane "Right"; SwitchToMode "Normal"; } 
        bind /*px*/ "x" { CloseFocus; SwitchToMode "Normal"; } 
        bind /*pc*/ "c" { MovePaneBackwards; }
        bind /*pf*/ "f" { ToggleFocusFullscreen; SwitchToMode "Normal"; }
    }
    shared_except "locked" {
        bind "i" { SwitchToMode "Locked"; } // enter insert mode
        bind "Ctrl q" { Quit; }
    }
}

EDIT: after posting this comment, and editing it over and over to improve readability, come to think of it, I realized that an issue should be opened for a feature request for binding key sequences, and I opened one (#2948), therefore, if you see this comment as off-topic, please mark it as such.

wis avatar Nov 18 '23 00:11 wis

I'd also like to express a desire to have custom modes. I'd like to put everything behind a "leader key" and while I can kind of get this behavior by using locked mode as the "leader" mode, that means I can't use locked mode as passthrough for input in emacs, etc.

Custom modes would allow me to create a top-level "mode" that can only be reached through one binding, and then everything else can be reached from there.

diminishedprime avatar Dec 17 '23 19:12 diminishedprime

I think implementing something like this, or allowing me to set some "leader" options by setting the locked mode, and then after my input going back to unlocked would be great. I can set locked to ctrl space just fine, but then I find myself hitting it again to go back in and out of locked mode after I have done my desired input.

A "vim" approach to modes would be cool, as I am trying to step away from tmux which goes very well with neovim as I like the batteries included of zellij. After maintaining my own neovim setup for years, now I build ontop of LazyVim, to me Zellij is similar in that dynamic for me regarding multiplexers. Sane defaults, nice useful things out the box, easy to customize (LazyVim makes it trivial with the Lazy package manager and extras you can enable).

Joseph-D-Bradshaw avatar May 06 '24 10:05 Joseph-D-Bradshaw