Move cursor with incremental search within current line.
CAVEATS
This plugin is the reinvention of the zsh's builtin feature ^R
and ^S
. These commands also allow you to move the cursor within the current line, though the name history-incremental-search is not obvious that they has the capability.
zplug "aoyama-val/zsh-incsearch"
Clone this repository and
source {PATH_TO_REPO}/zsh-incsearch.plugin.zsh
To your ~/.zshrc:
# bind to any keys you like
bindkey "^[l" incsearch-forward # put cursor at the end of match
bindkey "^[h" incsearch-backward # put cursor at the end of match
bindkey "^[L" incsearch-forward-beginning # put cursor at the beginning of match
bindkey "^[H" incsearch-backward-beginning # put cursor at the beginning of match
my_incsearch_hook_enter() {
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
# Change cursor to underline
echo -ne "\e]50;CursorShape=2\a"
fi
}
my_incsearch_hook_leave() {
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
# Restore cursor to block
echo -ne "\e]50;CursorShape=0\a"
fi
}
incsearch_hooks_enter+="my_incsearch_hook_enter"
incsearch_hooks_leave+="my_incsearch_hook_leave"
Key | Action |
---|---|
the key you bound to accept-line (usually Enter) |
Finish search |
the key you bound to backward-delete-char (usually Backspace) |
Delete the last character from the search text |