zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
21.23k stars 644 forks source link

Feature Request: allow binding π—Έπ—²π˜† π˜€π—²π—Ύπ˜‚π—²π—»π—°π—²π˜€, not just the binding of a single key, e.g `pj` to open a pane below #2948

Open wis opened 11 months ago

wis commented 11 months ago

here's my use case:

I want to be able to:

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; }
    }
}
Antiarchitect commented 6 months ago

Any progress on this? I saw https://github.com/zellij-org/zellij/issues/3201 and https://github.com/zellij-org/zellij/issues/248 Cool idea about virtual modes. Cool idea about Leader key + sequences (Spacemacs, Astronvim approach). Let me explain my case: Currently using tmux with backtick as the leader key. So backtick-c sequence creates new tab, backtick-x deletes tab, backtick-[ switches to copy mode, backtick-Esc cancels the operation started. All these are not combinations but sequences and all of them operates with different input modes in your terminology (as it seems to me). So I want the sequence to do the proper job (e.g. create tab) or be canceled by Esc and return back to the mode I called the sequence from. Sequences are widely used in Vim, Emacs, Spacemacs.

samholmes commented 4 months ago

Instead of binding key sequences, we could achieve the same result with "custom modes". First we bind p to enter a custom mode called "ModeP", then in that mode we can define "k" and "h" to their respective commands.

Additionally, we can apply a "backspace" keybinding to all modes to issue the hypothetical command "ReturnToLastMode" which will exit to the previous mode. Such a command implies that modes are maintained in a stack... So instead of having an unbounded stack-based mode system, we could opt to have "nested modes" where a mode can be nested in another mode and then we can have a command "GoToOuterMode" which will exit the current nested mode for the outer mode. Such a nested mode system could be complimented with some syntax to enter a nested mode deeply instead of always requiring nested modes be drilled down by commands. This flexibility could lead to a full state-machine with some contextual awareness via nesting.