A WIP Helix keybinding for Z Shell.
Bring comfort of working with Helix keybindings to your Zsh environment.
This plugin attempts to implement Helix keybindings as accurate and complete as much as possible. Any existing keybindings that should reflect the official default Helix keybinds but doesn't are considered bugs.
Features
- Accurate Helix replication! No more switching muscle memory.
- Helix's selection manipulation and movement.
- Match, Goto, Insert, Append, Change, Delete, Replace.
- Multi-cursor, Registers, Shell Pipe, Command mode!
- Yank-Paste for both registers and clipboard!
- Undo-Redo! And with selection history like Helix's.
- Multi-line mode. It's Helix editor right in your prompt!
- Cursor styling. Display different modes with different cursor looks.
Clone the repository to wherever you'd like and source the plugin.
git clone https://github.com/Multirious/zsh-helix-mode --depth 1
source ./zsh-helix-mode/zsh-helix-mode.plugin.zsh
Following zplug's plugin installation, add the below to your configuration:
zplug "multirious/zsh-helix-mode", depth:1, at:main
Following Antigen's plugin installation, add the below to your configuration:
antigen bundle multirious/zsh-helix-mode@main
Following Oh My Zsh's plugin installation, clone the repository to $ZSH_CUSTOM/plugins
folder:
git clone https://github.com/Multirious/zsh-helix-mode --depth 1 $ZSH_CUSTOM/plugins/zsh-helix-mode
And add the plugin to the plugins
array:
plugins=(zsh-helix-mode)
Nix (non-flake)
let
zsh-helix-mode = pkgs.fetchFromGithub {
owner = "multirious";
repo = "zsh-helix-mode";
rev = "...";
sha256 = "...";
};
in
''
source ${zsh-helix-mode}/zsh-helix-mode.plugin.zsh
''
{
inputs = {
zsh-helix-mode.url = "github:multirious/zsh-helix-mode/main"
};
}
You can change the cursor color and shape for each mode via these environment variables. The content of these variables should be a string of terminal escape sequences that modify the looks of your terminal cursor. These are printed everytime after mode changes.
ZHM_CURSOR_NORMAL
- Prints the variable whenever the mode changes to normal mode.
- By default, it is
\e[0m\e[2 q\e]12;#B4BEFE\a
which is a string of ANSI escape sequences
that basically means "reset, block cursor, pastel blue".
ZHM_CURSOR_SELECT
- Prints the variable whenever the mode changes to select mode.
- By default, it is
\e[0m\e[2 q\e]12;#F2CDCD\a
which is a string of ANSI escape sequences
that basically means "reset, block cursor, pastel red".
ZHM_CURSOR_INSERT
- Prints the variable whenever the mode changes to insert mode.
- By default, it is
\e[0m\e[5 q\e]12;white\a
which is a string of ANSI escape sequences
that basically means "reset, vertical blinking cursor, white".
ZHM_CLIPBOARD_PIPE_CONTENT_TO
- System yanked content will be piped to the command in this variable.
- By default, it is
xclip -sel clip
if theDISPLAY
environment variable is found,
orwl-copy
if theWAYLAND_DISPLAY
environment variable is found,
otherwise it is empty.
ZHM_CLIPBOARD_READ_CONTENT_FROM
- System paste will use the stdout output from the command in this variable.
- By default, it is
xclip -o -sel clip
if theDISPLAY
environment variable is found,
orwl-paste --no-newline
if theWAYLAND_DISPLAY
environment variable is found,
otherwise it is empty.
For zsh-autosuggestions
to work with zsh-helix-mode
you must configure zsh-autosuggestions
to use widgets implemented by this plugin:
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(
zhm_history_prev
zhm_history_next
zhm_prompt_accept
zhm_accept
zhm_accept_or_insert_newline
)
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(
zhm_move_right
)
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS+=(
zhm_move_next_word_start
zhm_move_next_word_end
)
More details here.
This still have some issues and that is partial accepting using zhm_move_next_word_start
or zhm_move_next_word_end
will leave one last character unaccepted which some can considered them undesirable/annoying (I know I am).
Please submit an issue/PR if you have a solution!
Due to how zsh-syntax-highlighting
works,
you must source the plugin after zsh-helix-mode
.
zsh-syntax-highlighting
can override zsh-helix-mode
's highlighting. To
mitigate the issue, please add the following after you've sourced zsh-syntax-highlighting
:
# source zsh-helix-mode
# source zsh-syntax-highlighting
zhm-add-update-region-highlight-hook
This section document some features that is different to Helix.
Press Alt-Enter
in any mode for toggling multi-line mode.
Press Ctrl-p
/Ctrl-n
in any mode for moving in the command history.
The register %
will returns the output of the pwd
command. Originally, it is "current file path" in Helix.
By pressing Alt-Enter
, the editor will be switched to multi-line mode.
In this mode, a message -- MULTILINE --
with a newline is prepended to your
commandline to ensure your first line in the buffer is at the same level
to any other lines. Pressing Enter
key in insert mode will add a newline
at your cursor instead of accepting the command. However, pressing Enter
key in normal mode is the same; it will accepts the current command as usual.
Other keys will behave the same.