zsh/bindings.zsh

113 lines
3.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/zsh
fpath=( "${ZDOTDIR:+$ZDOTDIR/widgets}" $fpath )
bindkey -v
2016-01-05 02:44:34 +00:00
typeset -A key
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Up]=${terminfo[kcuu1]}
key[Down]=${terminfo[kcud1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" yank
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-search
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-search
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" history-beginning-search-backward
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" history-beginning-search-forward
2020-04-02 16:21:55 +00:00
bindkey "\ee" expand-cmd-path # A-e for expanding path of typed command.
bindkey " " magic-space # Do history expansion on space.
bindkey $'\177' backward-delete-char # backspace
bindkey $'\10' backward-delete-word # C-backspace
2023-08-21 09:53:57 +00:00
autoload -U edit-command-line-split
zle -N edit-command-line-split
bindkey -M vicmd ! edit-command-line-split
#unicode input
autoload -U insert-unicode-char
zle -N insert-unicode-char
bindkey "^Vu" insert-unicode-char
bindkey "\e." insert-last-word
2016-01-05 02:44:34 +00:00
2014-06-27 05:43:45 +00:00
bindkey "\e[1;5D" vi-backward-blank-word
bindkey "\e[1;5C" vi-forward-blank-word
2019-07-11 15:43:30 +00:00
bindkey "^P" push-line-or-edit
2016-01-05 02:44:34 +00:00
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
2017-03-06 16:14:54 +00:00
local function zle-line-init () {
2018-03-11 11:18:44 +00:00
echoti smkx 2> /dev/null
2016-01-05 02:44:34 +00:00
}
2017-03-06 16:14:54 +00:00
local function zle-line-finish () {
2018-03-11 11:18:44 +00:00
echoti rmkx 2> /dev/null
2016-01-05 02:44:34 +00:00
}
zle -N zle-line-init
2023-08-21 09:53:57 +00:00
zle -N zle-line-finish
2016-07-22 14:01:35 +00:00
2021-06-18 10:09:38 +00:00
insert_sudo () { LBUFFER="sudo ${LBUFFER}" }
2016-07-22 14:01:35 +00:00
zle -N insert-sudo insert_sudo
bindkey "^[s" insert-sudo
local function accept-or-recall-and-infer-history() {
if [[ -z $PREBUFFER$BUFFER ]]; then
zle up-line-or-history
zle infer-next-history
else
zle accept-and-infer-next-history -- "$@"
fi
}
zle -N accept-or-recall-and-infer-history
2018-08-28 18:35:06 +00:00
bindkey "\e^M" accept-or-recall-and-infer-history
2018-08-28 18:35:06 +00:00
if exists incstring; then
local function inc-last-command() {
if [[ -z $BUFFER ]]; then
BUFFER=$(incstring "$(history -n -1)");
else
BUFFER=$(incstring "$BUFFER");
fi
zle vi-end-of-line
}
zle -N inc-last-command
bindkey "^A" inc-last-command
fi
2020-02-20 13:49:46 +00:00
if zle -l tmsu-fzf-change-directory; then
bindkey "^t" tmsu-fzf-change-directory
fi
2020-04-02 16:21:55 +00:00
2021-12-03 14:09:12 +00:00
zle-venv() { zle push-line; BUFFER="venv"; zle accept-line }
2020-04-02 16:21:55 +00:00
zle -N zle-venv
bindkey "\ev" zle-venv
2022-12-13 16:43:38 +00:00
# Map widgets to key
bindkey "\ec" fzf-change-directory
bindkey "^r" fzf-insert-history
bindkey "^xf" fzf-insert-files
bindkey "^xd" fzf-insert-directory
bindkey "^xn" fzf-insert-named-directory
FZF_CHANGE_DIR_FIND_COMMAND="fd -t d"
FZF_INSERT_DIR_COMMAND="fd -t d"
FZF_INSERT_FILES_COMMAND="fd -t f"
FZF_EDIT_FILES_COMMAND="fd -t f"
# modify history command to remove duplicates
FZF_HISTORY_COMMAND="fc -l 1 | sed 's/ *[0-9]* //g' | awk '!seen[\$0]++'"