diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-03-20 17:10:58 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-03-20 17:10:58 -0500 |
commit | ec5dc4d93af9c57304ecc2c5468ad10225707d71 (patch) | |
tree | ae4c9b6f1ba833a001b5bb8d0488fefbba7fbbfa /zsh/keybindings.zsh | |
parent | 59f0a992363e1d616531c6724b524ec191f9c61b (diff) |
feat: added configs
Diffstat (limited to 'zsh/keybindings.zsh')
-rw-r--r-- | zsh/keybindings.zsh | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/zsh/keybindings.zsh b/zsh/keybindings.zsh new file mode 100644 index 0000000..0dcaa25 --- /dev/null +++ b/zsh/keybindings.zsh @@ -0,0 +1,109 @@ +function r-delregion() { + if ((REGION_ACTIVE)) then + zle kill-region + else + local widget_name=$1 + shift + zle $widget_name -- $@ + fi +} + +function r-deselect() { + ((REGION_ACTIVE = 0)) + local widget_name=$1 + shift + zle $widget_name -- $@ +} + +function r-select() { + ((REGION_ACTIVE)) || zle set-mark-command + local widget_name=$1 + shift + zle $widget_name -- $@ +} + +function r-select-a() { + r-deselect beginning-of-line + r-select end-of-line +} + +function r-copy() { + if ((REGION_ACTIVE)) then + zle copy-region-as-kill + (( ${+aliases[cb]} )) && printf "$CUTBUFFER" | cb + else + zle kill-whole-line + fi +} + +function r-cut() { + if ((REGION_ACTIVE)) then + zle kill-region + else + zle kill-whole-line + fi + (( ${+aliases[cb]} )) && printf "$CUTBUFFER" | cb +} + +# Keybinds +for key kcap seq mode widget ( + sleft kLFT $'\e[1;2D' select backward-char + sright kRIT $'\e[1;2C' select forward-char + sup kri $'\e[1;2A' select up-line-or-history + sdown kind $'\e[1;2B' select down-line-or-history + + send kEND $'\E[1;2F' select end-of-line + send2 x $'\E[4;2~' select end-of-line + + shome kHOM $'\E[1;2H' select beginning-of-line + shome2 x $'\E[1;2~' select beginning-of-line + + left kcub1 $'\EOD' deselect backward-char + right kcuf1 $'\EOC' deselect forward-char + + end kend $'\EOF' deselect end-of-line + end2 x $'\E4~' deselect end-of-line + + home khome $'\EOH' deselect beginning-of-line + home2 x $'\E1~' deselect beginning-of-line + + csleft x $'\E[1;6D' select backward-word + csright x $'\E[1;6C' select forward-word + csend x $'\E[1;6F' select end-of-line + cshome x $'\E[1;6H' select beginning-of-line + + cleft x $'\E[1;5D' deselect backward-word + cright x $'\E[1;5C' deselect forward-word + + del kdch1 $'\E[3~' delregion delete-char + bs x $'^?' delregion backward-delete-char + + cc x "^C" copy "" + cx x "^X" cut "" + ca x "^A" select-a "" + ) { + eval "key-$key() { + r-$mode $widget \$@ + }" + zle -N key-$key + bindkey ${terminfo[$kcap]-$seq} key-$key +} + + +# register ctrl+c as interupt +function ctrl_c_intr() { + stty intr \^C <$TTY >$TTY +} + +# register ctrl+y as interupt +function ctrl_y_intr() { + stty intr \^Y <$TTY >$TTY +} + + +# make sure we can register hooks +autoload -Uz add-zsh-hook || return + +# register the functions as hooks +add-zsh-hook preexec ctrl_c_intr +add-zsh-hook precmd ctrl_y_intr
\ No newline at end of file |