1
0
Fork 0

zsh: clean up keymaps

This commit is contained in:
Luca Bilke 2024-10-16 11:52:11 +02:00
parent ab50b46751
commit 9d322e30d0
1 changed files with 75 additions and 17 deletions

View File

@ -1,24 +1,82 @@
#!/bin/zsh
WORDCHARS='*?_-.[]~&;!#$%^(){}<>'
# vi mode
bindkey -v
# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
zmodload zsh/terminfo
typeset -gA key_info
# Widgets
bindkey '^e' lfwrap
bindkey '^g' lg
bindkey '^z' togglefg
bindkey '^s' toggle-fzf-tab
bindkey -M vicmd '^v' edit-command-line
key_info=(
'Control' "\C-"
'Escape' "\e"
'Meta' "\M-"
'Backspace' "^?"
'Delete' "^[[3~"
'F1' "$terminfo[kf1]"
'F2' "$terminfo[kf2]"
'F3' "$terminfo[kf3]"
'F4' "$terminfo[kf4]"
'F5' "$terminfo[kf5]"
'F6' "$terminfo[kf6]"
'F7' "$terminfo[kf7]"
'F8' "$terminfo[kf8]"
'F9' "$terminfo[kf9]"
'F10' "$terminfo[kf10]"
'F11' "$terminfo[kf11]"
'F12' "$terminfo[kf12]"
'Insert' "$terminfo[kich1]"
'Home' "$terminfo[khome]"
'PageUp' "$terminfo[kpp]"
'End' "$terminfo[kend]"
'PageDown' "$terminfo[knp]"
'Up' "$terminfo[kcuu1]"
'Left' "$terminfo[kcub1]"
'Down' "$terminfo[kcud1]"
'Right' "$terminfo[kcuf1]"
'BackTab' "$terminfo[kcbt]"
'AltLeft' "${key_info[Escape]}${key_info[Left]} \e[1;3D"
'AltRight' "${key_info[Escape]}${key_info[Right]} \e[1;3C"
'ControlLeft' "\e[1;5D"
'ControlRight' "\e[1;5C"
'ControlPageUp' "\e[5;5~"
'ControlPageDown' "\e[6;5~"
)
local -A global_keybinds
global_keybinds=(
"$key_info[Home]" beginning-of-line
"$key_info[End]" end-of-line
"$key_info[Delete]" delete-char
"$key_info[ControlLeft]" backward-word
"$key_info[ControlRight]" forward-word
)
local -A viins_keybinds
viins_keybinds=(
"$key_info[Backspace]" backward-delete-char
"$key_info[Control]W" backward-kill-word
"$key_info[ControlLeft]" vi-backward-word
"$key_info[ControlRight]" vi-forward-word
"$key_info[Control]E" lfwrap
"$key_info[Control]G" lg
"$key_info[Control]S" toggle-fzf-tab
)
local -A vicmd_keybinds
vicmd_keybinds=(
"$key_info[Delete]" delete-char
"$key_info[ControlLeft]" vi-backward-word
"$key_info[ControlRight]" vi-forward-word
"$key_info[Control]V" edit-command-line
)
for key bind in ${(kv)global_keybinds} ${(kv)viins_keybinds}; do
bindkey -M viins "$key" "$bind"
done
for key bind in ${(kv)global_keybinds} ${(kv)vicmd_keybinds}; do
bindkey -M vicmd "$key" "$bind"
done
bindkey '^?' backward-delete-char
bindkey '^[[3~' delete-char
bindkey "^[[H" beginning-of-line
bindkey '^[[4~' end-of-line
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word