From cc9913210498e2d527486310f1e8a53b93f55ca8 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 31 Mar 2023 07:51:10 +0200 Subject: fix(vi-mode): fix check for prompt redisplay on mode change (#11547) --- plugins/vi-mode/vi-mode.plugin.zsh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'plugins/vi-mode') diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 9a410c1fb..d44be69d4 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -43,12 +43,25 @@ function _vi-mode-set-cursor-shape-for-keymap() { printf $'\e[%d q' "${_shape}" } +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 +72,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}" } @@ -138,13 +150,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}" } -- cgit v1.2.3-70-g09d2 From f7d903f3a31567f326d0f8ec2414722d0e3b992a Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 2 Apr 2023 13:40:49 +0200 Subject: fix(vi-mode): fix cursor change on visual mode (#11586) Fixes #11586 --- plugins/vi-mode/vi-mode.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins/vi-mode') diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index d44be69d4..cc9817a74 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -43,6 +43,13 @@ 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 -- cgit v1.2.3-70-g09d2 From df80a2da5475fc3c068bc5f700fa176a47f7adbe Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 2 Oct 2023 20:41:01 +0200 Subject: feat(vi-mode): copy to clipboard when using `vi-change*` and `vi-yank*` widgets (#11861) --- plugins/vi-mode/README.md | 6 ++++++ plugins/vi-mode/vi-mode.plugin.zsh | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'plugins/vi-mode') diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 0cb516751..821c12adb 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -144,11 +144,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` diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index cc9817a74..d1493e02f 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -147,8 +147,15 @@ 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} +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} + unfunction wrap_clipboard_widgets # if mode indicator wasn't setup by theme, define default, we'll leave INSERT_MODE_INDICATOR empty by default -- cgit v1.2.3-70-g09d2 From 5c22c5812ec8b980d223b8252edc7759dd354014 Mon Sep 17 00:00:00 2001 From: alps2006 Date: Tue, 24 Oct 2023 20:00:26 +0800 Subject: feat(vi-mode): allow replacing on visual mode (#12006) --- plugins/vi-mode/vi-mode.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/vi-mode') diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index d1493e02f..8fefaf86c 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -154,7 +154,8 @@ wrap_clipboard_widgets copy \ vi-delete vi-delete-char vi-backward-delete-char wrap_clipboard_widgets paste \ - vi-put-{before,after} + vi-put-{before,after} \ + put-replace-selection unfunction wrap_clipboard_widgets -- cgit v1.2.3-70-g09d2