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

Re: zle: vi mode: wrong undo handling on fresh lines



On 29 Jan, I wrote:
> If someone has the overstrike option set, it should probably be 'R'.
> Actually that option seems to be fully non-working for vi mode.

It seems overstrike in vi mode is something we only just broke. This
fixes it. Also, having collectively put some thought into what the
synthesised vi command should be when repeating the first change, I
thought it'd be a waste not to do something â?? even though it is a
feature that nobody has ever missed. This uses 'o' for blank lines,
mainly because it is the most useful, 'R' if overstrike is set, 'a' if
the cursor is at the end of a non-blank line and 'i' otherwise.

Oliver

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index ed8577b..b0010fc 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1198,14 +1198,6 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
     statusline = NULL;
     selectkeymap("main", 1);
     initundo();
-    /*
-     * If main is linked to the viins keymap, we need to register
-     * explicitly that we're now in vi insert mode as there's
-     * no user operation to indicate this.
-     */
-    if (openkeymap("main") == openkeymap("viins"))
-	viinsert_init();
-    selectlocalmap(NULL);
     fixsuffix();
     if ((s = getlinknode(bufstack))) {
 	setline(s, ZSL_TOEND);
@@ -1222,6 +1214,14 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
 	    stackhist = -1;
 	}
     }
+    /*
+     * If main is linked to the viins keymap, we need to register
+     * explicitly that we're now in vi insert mode as there's
+     * no user operation to indicate this.
+     */
+    if (openkeymap("main") == openkeymap("viins"))
+	viinsert_init();
+    selectlocalmap(NULL);
     if (isset(PROMPTCR))
 	putc('\r', shout);
     if (tmout)
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 79b8cb9..994b44f 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -79,8 +79,9 @@ static void
 startvichange(int im)
 {
     if (im != -1) {
-	insmode = im;
 	vichgflag = 1;
+	if (im > -1)
+	    insmode = im;
     }
     if (inrepeat && im != -2) {
 	zmod = lastmod;
@@ -92,7 +93,8 @@ startvichange(int im)
 	    free(vichgbuf);
 	vichgbuf = (char *)zalloc(vichgbufsz = 16);
 	if (im == -2) {
-	    vichgbuf[0] = 'a';
+	    vichgbuf[0] =
+		zlell ? (insmode ? (zlecs < zlell ? 'i' : 'a') : 'R') : 'o';
 	} else {
 	    vichgbuf[0] = lastchar;
 	}



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