Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active January 8, 2023 14:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save YumaInaura/e53cd4e128b5625caac1f28dad74ba94 to your computer and use it in GitHub Desktop.
Save YumaInaura/e53cd4e128b5625caac1f28dad74ba94 to your computer and use it in GitHub Desktop.
Zsh — How to create user defined widget and map with bindkey ( For very beginner of zle )

Zsh — How to create user defined widget and map with bindkey ( For very beginner of zle )

Another titles

  • How to add customized event and bind keymap
  • The very beginner to zle of zsh keymapping with bindkey

Step. Create function in shell

double-up-history() { zle up-history; zle up-history }

Step. Register function as custom "widget"

zle -N double-up-history

Step. Bind costom widget to key you like

In this example bind alphabet "d".

bindkey d double-up-history

Try

echo 1
1

echo 2
2

echo 3
3

# hit d

echo 2 

You will see echo 2 not echo 3. upto-history twice succceded!

Next try

Let’s bind now created custom widget `double-up-history to another key!

b
bi
bin
echo 2
echo 2k
echo 2ke
echo 2key

Oh what's happend?

Remember you binded keymap "d" to double-up-history widget. So you can not hit "d" alphabet never.

But do not warry. Once close your console and re-opening resolves that problem.

All customized mapped bindkey will be reset.

rc file example

source ~/.zshrc

double-up-history() {
  zle up-history
  zle up-history
}

zle -N double-up-history

bindkey d double-up-history

Versions

  • zsh 5.5.1 (x86_64-apple-darwin17.5.0)

Ref

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment