Improve vi mode
authorMikael Berthe <mikael.berthe@cnamts.fr>
Sun, 25 Apr 2021 13:40:43 +0200
changeset 47 f25fda256b1d
parent 46 757c82badf6c
child 48 604330c024f4
Improve vi mode
zshrc.d/10-default-bindings.zrc
zshrc.d/60-vi-showmode.zrc
--- a/zshrc.d/10-default-bindings.zrc	Sat Aug 22 12:02:41 2020 +0200
+++ b/zshrc.d/10-default-bindings.zrc	Sun Apr 25 13:40:43 2021 +0200
@@ -16,8 +16,9 @@
 bindkey -s '' '^[/'
 bindkey -s '' '^[,'
 
-# Sur la console
-if [[ "$TERM" == "console" || "$TERM" == "vt100" ]]; then
+if [[ $TERM == "console" || $TERM == "vt100" || $TERM == linux* ||
+      $TERM == xterm* || $TERM == tmux* ]]
+then
   bindkey '^[[1~' beginning-of-line       # Home
   bindkey '^[[4~' end-of-line             # End
 fi
@@ -26,16 +27,12 @@
 if [[ -z ${TERM:#linux*} || -z ${TERM:#screen} ]]; then
   bindkey '^[[H'  beginning-of-line       # Home
   bindkey '^[[F'  end-of-line             # End
-  bindkey '^[[1~'  beginning-of-line       # Home
-  bindkey '^[[4~'  end-of-line             # End
 fi
 
 # Dans un xterm
 if [[ -z ${TERM:#xterm*} ]]; then
   bindkey '^[[H'  beginning-of-line       # Home
   bindkey '^[[F'  end-of-line             # End
-  bindkey '^[[1~'  beginning-of-line       # Home
-  bindkey '^[[4~'  end-of-line             # End
 
   # Sur un xterm, on differencie backspace et delete (?).
   bindkey '^H'  backward-delete-char    # Backspace
--- a/zshrc.d/60-vi-showmode.zrc	Sat Aug 22 12:02:41 2020 +0200
+++ b/zshrc.d/60-vi-showmode.zrc	Sun Apr 25 13:40:43 2021 +0200
@@ -179,6 +179,11 @@
 ###
 
 vi-replace() {
+   if [[ $ZLE_STATE == *overwrite* ]]; then # Switch back to insert mode
+       builtin zle .vi-insert
+       redisplay-insert
+       return
+   fi
    show_mode "$__string_replace"
    builtin zle .vi-replace
 }
@@ -211,7 +216,7 @@
 bindkey -M vicmd 'guw'   down-case-word
 bindkey -M vicmd 'gUw'   up-case-word
 
-bindkey -M vicmd "^[[2~" vi-insert
+bindkey -M vicmd '^[[2~' vi-insert
 bindkey -M vicmd 'q'     push-line
 
 # Specific to insert mode
@@ -221,6 +226,8 @@
 bindkey -M viins '^[[5~' history-beginning-search-backward # PgUp
 bindkey -M viins '^[[6~' history-beginning-search-forward  # PgDn
 
+bindkey -M viins '^[[2~' vi-replace
+
 bindkey -M viins '^[[A'  up-line-or-history
 bindkey -M viins '^[[B'  down-line-or-history
 
@@ -256,7 +263,7 @@
 bindkey '^I' ft-complete
 
 
-if [[ -z ${TERM:#screen} ]]; then
+if [[ $TERM == screen* || $TERM == tmux* ]]; then
   bindkey -M viins '^[[1~'  beginning-of-line   # Home
   bindkey -M vicmd '^[[1~'  beginning-of-line   # Home
   bindkey -M viins '^[[4~'  end-of-line         # End