zsh: history: add improved history search functionality

This commit is contained in:
Thomas Preisner 2017-07-10 02:57:48 +02:00
parent f5bb986514
commit 7c64d5a801

View file

@ -2,3 +2,28 @@
HISTSIZE=1000000 HISTSIZE=1000000
SAVEHIST=1000000 SAVEHIST=1000000
HISTFILE=~/.zsh/zsh_history HISTFILE=~/.zsh/zsh_history
# ===== functions
# vim-like completion of previous executed commands. Depending on cursor
# position it either behaves like cursor up/down or includes already typed
# text.
zle -N zshrc-vi-history-beginning-search-backward
zshrc-vi-history-beginning-search-backward()
{
local not_at_beginning_of_line
if [[ $CURSOR -ne 0 ]]; then
not_at_beginning_of_line=yes
fi
zle history-beginning-search-backward
# start Vi-mode and stay at the same position (Vi-mode moves one left,
# this counters it).
zle vi-cmd-mode
if [[ -n $not_at_beginning_of_line ]]; then
zle vi-forward-char
fi
}
# only ^P bind is necessary as ^P enters Vi-Mode and ^N only makes sense after calling ^P
bindkey '^P' zshrc-vi-history-beginning-search-backward