Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: History Up key



> I am using vi key binding. When I want to repeare my repeat command, I used
> to hit the "cursor-up" key, see the last command and hit enter. The fact that
> I am at vi-insert-mode still allowed the binding of "cursor-up" to
> "up-line-or-history". 
> 
> However, upgrading to zsh 4, the binding apparently disappeared, and I
> have to hit the escape key before the cursor-up to go into
> vi-command-mode. I think this behavior is the same as in bash, but I find
> it a little annoying. Is this intentional? Is there any setting I can  do
> to have the old behavior?

This has been in the FAQ for some time (see below).  The change was made, I
think by Zefram, when the vi insert and vi command keymaps were made
properly separate keymaps: before that, if I remember rightly, only the
first key in the sequence was really distinct and prefix keys used a common
table.  So it was a side effect of the old implementation that it worked at
all.

But I can't for the life of me see why we shouldn't bind them by default in
vi insert mode.  The patch at the bottom does this.  Can anybody see why
this would be a problem?  (There's a timeout given by the parameter
$KEYTIMEOUT after which an escape is no longer treated as a prefix key and
switches to command mode, so you might notice a slight extra delay doing
that.)


  o  In vi insert mode, the cursor keys no longer work.  The following
     will bind them:

       bindkey -M viins '^[[D' vi-backward-char '^[[C' vi-forward-char \ 
                      '^[[A' up-line-or-history '^[[B' down-line-or-history

     (unless your terminal requires `^[O' instead of `^[[').  The
     rationale is that the insert mode and command mode keymaps for
     keys with prefixes are now separate.

Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.3
diff -u -r1.3 zle_keymap.c
--- Src/Zle/zle_keymap.c	2000/12/18 02:14:57	1.3
+++ Src/Zle/zle_keymap.c	2001/03/12 10:32:37
@@ -1023,6 +1023,7 @@
     Keymap emap = newkeymap(NULL, "emacs");
     Keymap amap = newkeymap(NULL, "vicmd");
     Keymap smap = newkeymap(NULL, ".safe");
+    Keymap vimaps[2], kptr;
     char buf[3], *ed;
     int i;
 
@@ -1066,15 +1067,20 @@
     /* vt100 arrow keys are bound by default, for historical reasons. *
      * Both standard and keypad modes are supported.                  */
 
-    /* vi command mode: arrow keys */
-    bindkey(amap, "\33[A",  refthingy(t_uplineorhistory), NULL);
-    bindkey(amap, "\33[B",  refthingy(t_downlineorhistory), NULL);
-    bindkey(amap, "\33[C",  refthingy(t_viforwardchar), NULL);
-    bindkey(amap, "\33[D",  refthingy(t_vibackwardchar), NULL);
-    bindkey(amap, "\33OA",  refthingy(t_uplineorhistory), NULL);
-    bindkey(amap, "\33OB",  refthingy(t_downlineorhistory), NULL);
-    bindkey(amap, "\33OC",  refthingy(t_viforwardchar), NULL);
-    bindkey(amap, "\33OD",  refthingy(t_vibackwardchar), NULL);
+    vimaps[0] = vmap;
+    vimaps[1] = amap;
+    for (i = 0; i < 2; i++) {
+	kptr = vimaps[i];
+	/* vi command and insert modes: arrow keys */
+	bindkey(kptr, "\33[A",  refthingy(t_uplineorhistory), NULL);
+	bindkey(kptr, "\33[B",  refthingy(t_downlineorhistory), NULL);
+	bindkey(kptr, "\33[C",  refthingy(t_viforwardchar), NULL);
+	bindkey(kptr, "\33[D",  refthingy(t_vibackwardchar), NULL);
+	bindkey(kptr, "\33OA",  refthingy(t_uplineorhistory), NULL);
+	bindkey(kptr, "\33OB",  refthingy(t_downlineorhistory), NULL);
+	bindkey(kptr, "\33OC",  refthingy(t_viforwardchar), NULL);
+	bindkey(kptr, "\33OD",  refthingy(t_vibackwardchar), NULL);
+    }
 
     /* emacs mode: arrow keys */
     bindkey(emap, "\33[A",  refthingy(t_uplineorhistory), NULL);
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.9
diff -u -r1.9 zle.yo
--- Doc/Zsh/zle.yo	2000/09/20 06:58:54	1.9
+++ Doc/Zsh/zle.yo	2001/03/12 10:32:37
@@ -222,7 +222,7 @@
 Move backward one character.
 )
 tindex(vi-backward-char)
-item(tt(vi-backward-char) (unbound) (^H h ^?) (unbound))(
+item(tt(vi-backward-char) (unbound) (^H h ^?) (ESC-[D))(
 Move backward one character, without changing lines.
 )
 tindex(backward-word)
@@ -273,7 +273,7 @@
 Move forward one character.
 )
 tindex(vi-forward-char)
-item(tt(vi-forward-char) (unbound) (space l) (unbound))(
+item(tt(vi-forward-char) (unbound) (space l) (ESC-[C))(
 Move forward one character.
 )
 tindex(vi-find-next-char)
@@ -357,7 +357,7 @@
 Move to the first event in the history list.
 )
 tindex(down-line-or-history)
-item(tt(down-line-or-history) (^N ESC-[B) (j) (unbound))(
+item(tt(down-line-or-history) (^N ESC-[B) (j) (ESC-[B))(
 Move down a line in the buffer, or if already at the bottom line,
 move to the next event in the history list.
 )
@@ -546,7 +546,7 @@
 Repeat the last vi history search, but in reverse.
 )
 tindex(up-line-or-history)
-item(tt(up-line-or-history) (^P ESC-[A) (k) (unbound))(
+item(tt(up-line-or-history) (^P ESC-[A) (k) (ESC-[A))(
 Move up a line in the buffer, or if already at the top line,
 move to the previous event in the history list.
 )

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



Messages sorted by: Reverse Date, Date, Thread, Author