0e833b622ba43d38bd62227244d831f3c0e4a325

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

refactor(vi-mode): remove duplicate bindkey logic and fix syntax

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh
  2index 7ff826ea314af8943401b6f70f747199304f7eef..f83ea76968d2ab4c5d93ce2851bab7ceae4c084a 100644
  3--- a/plugins/vi-mode/vi-mode.plugin.zsh
  4+++ b/plugins/vi-mode/vi-mode.plugin.zsh
  5@@ -31,7 +31,7 @@ function zle-keymap-select() {
  6   # update keymap variable for the prompt
  7   typeset -g VI_KEYMAP=$KEYMAP
  8 
  9-  if [ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]; then
 10+  if [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]]; then
 11     zle reset-prompt
 12     zle -R
 13   fi
 14@@ -73,84 +73,41 @@ bindkey '^s' history-incremental-search-forward
 15 bindkey '^a' beginning-of-line
 16 bindkey '^e' end-of-line
 17 
 18-if [[ "${terminfo[kpp]}" != "" ]]; then
 19-  bindkey "${terminfo[kpp]}" up-line-or-history       # [PageUp] - Up a line of history
 20-fi
 21-if [[ "${terminfo[knp]}" != "" ]]; then
 22-  bindkey "${terminfo[knp]}" down-line-or-history     # [PageDown] - Down a line of history
 23-fi
 24-
 25-# start typing + [Up-Arrow] - fuzzy find history forward
 26-if [[ "${terminfo[kcuu1]}" != "" ]]; then
 27-  autoload -U up-line-or-beginning-search
 28-  zle -N up-line-or-beginning-search
 29-  bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
 30-fi
 31-# start typing + [Down-Arrow] - fuzzy find history backward
 32-if [[ "${terminfo[kcud1]}" != "" ]]; then
 33-  autoload -U down-line-or-beginning-search
 34-  zle -N down-line-or-beginning-search
 35-  bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
 36-fi
 37-
 38-if [[ "${terminfo[khome]}" != "" ]]; then
 39-  bindkey "${terminfo[khome]}" beginning-of-line      # [Home] - Go to beginning of line
 40-fi
 41-if [[ "${terminfo[kend]}" != "" ]]; then
 42-  bindkey "${terminfo[kend]}"  end-of-line            # [End] - Go to end of line
 43-fi
 44-
 45-if [[ "${terminfo[kcbt]}" != "" ]]; then
 46-  bindkey "${terminfo[kcbt]}" reverse-menu-complete   # [Shift-Tab] - move through the completion menu backwards
 47-fi
 48-
 49-bindkey '^?' backward-delete-char                     # [Backspace] - delete backward
 50-if [[ "${terminfo[kdch1]}" != "" ]]; then
 51-  bindkey "${terminfo[kdch1]}" delete-char            # [Delete] - delete forward
 52-else
 53-  bindkey "^[[3~" delete-char
 54-  bindkey "^[3;5~" delete-char
 55-  bindkey "\e[3~" delete-char
 56-fi
 57-
 58-() {
 59-  local wrap_clipboard_widgets
 60-  function wrap_clipboard_widgets() {
 61-    # NB: Assume we are the first wrapper and that we only wrap native widgets
 62-    # See zsh-autosuggestions.zsh for a more generic and more robust wrapper
 63-    local verb="$1"
 64-    shift
 65-
 66-    local widget
 67-    local wrapped_name
 68-    for widget in "$@"; do
 69-      wrapped_name="_zsh-vi-${verb}-${widget}"
 70-      if [ "${verb}" = copy ]; then
 71-        eval "
 72-          function ${wrapped_name}() {
 73-            zle .${widget}
 74-            printf %s \"\${CUTBUFFER}\" | clipcopy
 75-          }
 76-        "
 77-      else
 78-        eval "
 79-          function ${wrapped_name}() {
 80-            CUTBUFFER=\"\$(clippaste)\"
 81-            zle .${widget}
 82-          }
 83-        "
 84-      fi
 85-      zle -N "${widget}" "${wrapped_name}"
 86-    done
 87-  }
 88-
 89-  wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete
 90-  wrap_clipboard_widgets paste vi-put-{before,after}
 91-  unfunction wrap_clipboard_widgets
 92+function wrap_clipboard_widgets() {
 93+  # NB: Assume we are the first wrapper and that we only wrap native widgets
 94+  # See zsh-autosuggestions.zsh for a more generic and more robust wrapper
 95+  local verb="$1"
 96+  shift
 97+
 98+  local widget
 99+  local wrapped_name
100+  for widget in "$@"; do
101+    wrapped_name="_zsh-vi-${verb}-${widget}"
102+    if [ "${verb}" = copy ]; then
103+      eval "
104+        function ${wrapped_name}() {