Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
- X-seq: zsh-workers 42929
 
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
 
- To: Zsh hackers list <zsh-workers@xxxxxxx>
 
- Subject: [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
 
- Date: Mon, 4 Jun 2018 13:17:34 +0200
 
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com; s=20161025;        h=mime-version:from:date:message-id:subject:to;        bh=oiQr5YrzR6tbgJT2ep6uMPyYdvLYlbyOt0OBjIkurdc=;        b=mO5RuhBKmI475VkVc4ZGXGgOKA//IUjZlPiJRpTgiIaUuENmFqrU9VEcLKDRZXcKRg         Yw6Ye4MRAj6XByqfHtmdtUYhpCORiDyH1lol0JrlOzyVo2AIsF3iWj6OtbnTXFfzXXPv         4DQSHPv/OkNslmtj0PTgGfGT5TPujTGBTPhsZP2/Z/JNwMI4vkEu+pgUKoQl84GUUS7I         EP1js6X4aztE8JPMl/xQ4lETZXRnVHuZZJTEkZxunBmYU+6KJUo9TxSireqOA+BPrdfA         idewdB7VmKLP3cm1fPNoI/xA8pwoKOe9dfGvcptcJVHfygmbKZxMs15CnQg7oEdQatcU         TQWA==
 
- List-help: <mailto:zsh-workers-help@zsh.org>
 
- List-id: Zsh Workers List <zsh-workers.zsh.org>
 
- List-post: <mailto:zsh-workers@zsh.org>
 
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
 
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
 
Hello,
the page up / page down bindings that I've added earlier were only for
insert mode. The patch binds them also in vicmd.
Other basic editor keys are Home, End, moving cursor to beginning or
end of line. I've added bindings for them, both to emacs/insert and to
vicmd. $terminfo was wrong about my khome, kend codes, so I've also
added a fallback bindings. I think such fallbacks is what normal
projects are doing – accumulate real-world situations.
-- 
Best regards,
Sebastian Gniazdowski
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index f571daf..7368439 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -3,7 +3,7 @@
 #
 # No other shell could do this.
 # Edit small files with the command line editor.
-# Use ^X^W to save, ^C to abort.
+# Use ^X^W to save (or ZZ in vicmd mode), ^C to abort.
 # Option -f: edit shell functions.  (Also if called as fned.)
 
 setopt localoptions noksharrays
@@ -60,6 +60,11 @@ __zed_pg_down()
     done
 }
 
+if ! zle -la __zed_pg_up __zed_pg_down; then
+    zle -N __zed_pg_up
+    zle -N __zed_pg_down
+fi
+
 if (( bind )) || ! bindkey -M zed >&/dev/null; then
   # Make the zed keymap a copy of the current main.
   bindkey -N zed main
@@ -75,10 +80,16 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
   bindkey -M zed '^x^w' accept-line
   bindkey -M zed '^M' self-insert-unmeta
 
-  zle -N __zed_pg_up
-  zle -N __zed_pg_down
-  [[ ${+terminfo} = 1 && -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
-  [[ ${+terminfo} = 1 && -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+  [[ ${+terminfo} = 1 ]] && {
+    [[  -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed "$terminfo[khome]" beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed "$terminfo[kend]" end-of-line
+
+    # Fallback to well known code as terminfo might be wrong (often) sometimes
+    bindkey -M zed-vicmd "^[[H" beginning-of-line
+    bindkey -M zed-vicmd "^[[F" end-of-line
+  }
 
   # Make zed-set-file-name available.
   # Assume it's in fpath; there's no error at this point if it isn't
@@ -89,6 +100,16 @@ if (( bind )) || ! bindkey -M zed-vicmd >&/dev/null; then
   bindkey -N zed-vicmd vicmd
 
   bindkey -M zed-vicmd "ZZ" accept-line
+  [[ ${+terminfo} = 1 ]] && {
+    [[ -n "$terminfo[kpp]" ]] && bindkey -M zed-vicmd "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed-vicmd "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed-vicmd "$terminfo[khome]" vi-beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed-vicmd "$terminfo[kend]" vi-end-of-line
+
+    # Fallback to well known code as terminfo might be wrong (often) sometimes
+    bindkey -M zed-vicmd "^[[H" vi-beginning-of-line
+    bindkey -M zed-vicmd "^[[F" vi-end-of-line
+  }
 fi
 
 (( bind )) && return 0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author