mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Vastly improved oh-my-zsh vi-mode plugin.
This commit is contained in:
parent
26e61bb5b4
commit
d7c176f6e6
1 changed files with 42 additions and 13 deletions
|
|
@ -1,22 +1,51 @@
|
||||||
function zle-line-init zle-keymap-select {
|
# Allow command line editing in an external editor.
|
||||||
|
autoload -Uz edit-command-line
|
||||||
|
|
||||||
|
# If mode indicator wasn't setup by theme, define a default.
|
||||||
|
if [[ "$MODE_INDICATOR" == "" ]]; then
|
||||||
|
MODE_INDICATOR="%{$fg_bold[red]%}<%{$reset_color%}%{$fg[red]%}<<%{$reset_color%}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function zle-line-init {
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If I am using vi keys, I want to know what mode I'm currently using.
|
||||||
|
# zle-keymap-select is executed every time KEYMAP changes.
|
||||||
|
# From http://zshwiki.org/home/examples/zlewidgets
|
||||||
|
rprompt_cached=$RPROMPT
|
||||||
|
function zle-line-init zle-keymap-select {
|
||||||
|
RPROMPT="${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/$rprompt_cached}"
|
||||||
|
zle reset-prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
# Accept RETURN in vi command mode.
|
||||||
|
function accept_line {
|
||||||
|
RPROMPT=$rprompt_cached
|
||||||
|
builtin zle .accept-line
|
||||||
|
}
|
||||||
|
|
||||||
zle -N zle-line-init
|
zle -N zle-line-init
|
||||||
zle -N zle-keymap-select
|
zle -N zle-keymap-select
|
||||||
|
zle -N accept_line
|
||||||
|
zle -N edit-command-line
|
||||||
|
|
||||||
bindkey -v
|
# Avoid binding ^J, ^M, ^C, ^?, ^S, ^Q, etc.
|
||||||
|
bindkey -d # Reset to default.
|
||||||
|
bindkey -v # Use vi key bindings.
|
||||||
|
bindkey -M vicmd "^M" accept_line # Alow RETURN in vi command.
|
||||||
|
bindkey -M vicmd v edit-command-line # ESC-v to edit in an external editor.
|
||||||
|
|
||||||
# if mode indicator wasn't setup by theme, define default
|
bindkey ' ' magic-space
|
||||||
if [[ "$MODE_INDICATOR" == "" ]]; then
|
bindkey -M vicmd "gg" beginning-of-history
|
||||||
MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
|
bindkey -M vicmd "G" end-of-history
|
||||||
fi
|
bindkey -M vicmd "k" history-search-backward
|
||||||
|
bindkey -M vicmd "j" history-search-forward
|
||||||
|
bindkey -M vicmd "?" history-incremental-search-backward
|
||||||
|
bindkey -M vicmd "/" history-incremental-search-forward
|
||||||
|
|
||||||
function vi_mode_prompt_info() {
|
bindkey -M viins "^L" clear-screen
|
||||||
echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
|
bindkey -M viins "^W" backward-kill-word
|
||||||
}
|
bindkey -M viins "^A" beginning-of-line
|
||||||
|
bindkey -M viins "^E" end-of-line
|
||||||
|
|
||||||
# define right prompt, if it wasn't defined by a theme
|
|
||||||
if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
|
|
||||||
RPS1='$(vi_mode_prompt_info)'
|
|
||||||
fi
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue