mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
merge
This commit is contained in:
parent
a8c56f5231
commit
8274156fae
296 changed files with 6279 additions and 3141 deletions
|
|
@ -37,6 +37,8 @@ plugins=(... vi-mode)
|
|||
- `INSERT_MODE_INDICATOR`: controls the string displayed when the shell is in insert mode.
|
||||
See [Mode indicators](#mode-indicators) for details.
|
||||
|
||||
- `VI_MODE_DISABLE_CLIPBOARD`: If set, disables clipboard integration on yank/paste
|
||||
|
||||
## Mode indicators
|
||||
|
||||
*Normal mode* is indicated with a red `<<<` mark at the right prompt, when it
|
||||
|
|
@ -53,7 +55,7 @@ INSERT_MODE_INDICATOR="%F{yellow}+%f"
|
|||
|
||||
### Adding mode indicators to your prompt
|
||||
|
||||
`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by
|
||||
`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by
|
||||
a preceding plugin.
|
||||
|
||||
If `PROMPT` or `RPROMPT` is not defined to your liking, you can add mode info manually. The `vi_mode_prompt_info` function is available to insert mode indicator information.
|
||||
|
|
@ -144,11 +146,17 @@ NOTE: this used to be bound to `v`. That is now the default (`visual-mode`).
|
|||
- `c{motion}` : Delete {motion} text and start insert
|
||||
- `cc` : Delete line and start insert
|
||||
- `C` : Delete to the end of the line and start insert
|
||||
- `P` : Insert the contents of the clipboard before the cursor
|
||||
- `p` : Insert the contents of the clipboard after the cursor
|
||||
- `r{char}` : Replace the character under the cursor with {char}
|
||||
- `R` : Enter replace mode: Each character replaces existing one
|
||||
- `x` : Delete `count` characters under and after the cursor
|
||||
- `X` : Delete `count` characters before the cursor
|
||||
|
||||
NOTE: delete/kill commands (`dd`, `D`, `c{motion}`, `C`, `x`,`X`) and yank commands
|
||||
(`y`, `Y`) will copy to the clipboard. Contents can then be put back using paste commands
|
||||
(`P`, `p`).
|
||||
|
||||
## Known issues
|
||||
|
||||
### Low `$KEYTIMEOUT`
|
||||
|
|
|
|||
|
|
@ -43,12 +43,32 @@ function _vi-mode-set-cursor-shape-for-keymap() {
|
|||
printf $'\e[%d q' "${_shape}"
|
||||
}
|
||||
|
||||
function _visual-mode {
|
||||
typeset -g VI_KEYMAP=visual
|
||||
_vi-mode-set-cursor-shape-for-keymap "$VI_KEYMAP"
|
||||
zle .visual-mode
|
||||
}
|
||||
zle -N visual-mode _visual-mode
|
||||
|
||||
function _vi-mode-should-reset-prompt() {
|
||||
# If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset (default), dynamically
|
||||
# check whether we're using the prompt to display vi-mode info
|
||||
if [[ -z "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" ]]; then
|
||||
[[ "${PS1} ${RPS1}" = *'$(vi_mode_prompt_info)'* ]]
|
||||
return $?
|
||||
fi
|
||||
|
||||
# If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE was manually set, let's check
|
||||
# if it was specifically set to true or it was disabled with any other value
|
||||
[[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE}" = true ]]
|
||||
}
|
||||
|
||||
# Updates editor information when the keymap changes.
|
||||
function zle-keymap-select() {
|
||||
# update keymap variable for the prompt
|
||||
typeset -g VI_KEYMAP=$KEYMAP
|
||||
|
||||
if [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]]; then
|
||||
if _vi-mode-should-reset-prompt; then
|
||||
zle reset-prompt
|
||||
zle -R
|
||||
fi
|
||||
|
|
@ -59,10 +79,9 @@ zle -N zle-keymap-select
|
|||
# These "echoti" statements were originally set in lib/key-bindings.zsh
|
||||
# Not sure the best way to extend without overriding.
|
||||
function zle-line-init() {
|
||||
local prev_vi_keymap
|
||||
prev_vi_keymap="${VI_KEYMAP:-}"
|
||||
local prev_vi_keymap="${VI_KEYMAP:-}"
|
||||
typeset -g VI_KEYMAP=main
|
||||
[[ "$prev_vi_keymap" != 'main' ]] && [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]] && zle reset-prompt
|
||||
[[ "$prev_vi_keymap" != 'main' ]] && _vi-mode-should-reset-prompt && zle reset-prompt
|
||||
(( ! ${+terminfo[smkx]} )) || echoti smkx
|
||||
_vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}"
|
||||
}
|
||||
|
|
@ -128,9 +147,19 @@ function wrap_clipboard_widgets() {
|
|||
done
|
||||
}
|
||||
|
||||
wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete vi-delete-char
|
||||
wrap_clipboard_widgets paste vi-put-{before,after}
|
||||
unfunction wrap_clipboard_widgets
|
||||
if [[ -z "${VI_MODE_DISABLE_CLIPBOARD:-}" ]]; then
|
||||
wrap_clipboard_widgets copy \
|
||||
vi-yank vi-yank-eol vi-yank-whole-line \
|
||||
vi-change vi-change-eol vi-change-whole-line \
|
||||
vi-kill-line vi-kill-eol vi-backward-kill-word \
|
||||
vi-delete vi-delete-char vi-backward-delete-char
|
||||
|
||||
wrap_clipboard_widgets paste \
|
||||
vi-put-{before,after} \
|
||||
put-replace-selection
|
||||
|
||||
unfunction wrap_clipboard_widgets
|
||||
fi
|
||||
|
||||
# if mode indicator wasn't setup by theme, define default, we'll leave INSERT_MODE_INDICATOR empty by default
|
||||
if [[ -z "$MODE_INDICATOR" ]]; then
|
||||
|
|
@ -138,13 +167,6 @@ if [[ -z "$MODE_INDICATOR" ]]; then
|
|||
fi
|
||||
|
||||
function vi_mode_prompt_info() {
|
||||
# If we're using the prompt to display mode info, and we haven't explicitly
|
||||
# disabled "reset prompt on mode change", then set it here.
|
||||
#
|
||||
# We do that here instead of the `if` statement below because the user may
|
||||
# set RPS1/RPROMPT to something else in their custom config.
|
||||
: "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:=true}"
|
||||
|
||||
echo "${${VI_KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/$INSERT_MODE_INDICATOR}"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue