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

PATCH: vi-backward-word-end widgets



In vim, ge and gE go back to the end of the previous word. I've had this
in my own configuration with a shell widget but that isn't perfect. This
adds native C widgets.

Oliver

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index c549990..bf1b315 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -1049,6 +1049,11 @@ item(tt(vi-backward-blank-word) (unbound) (B) (unbound))(
 Move backward one word, where a word is defined as a series of
 non-blank characters.
 )
+tindex(vi-backward-blank-word-end)
+item(tt(vi-backward-blank-word-end) (unbound) (unbound) (unbound))(
+Move to the end of the previous word, where a word is defined as a
+series of non-blank characters.
+)
 tindex(backward-char)
 item(tt(backward-char) (^B ESC-[D) (unbound) (unbound))(
 Move backward one character.
@@ -1069,6 +1074,10 @@ tindex(vi-backward-word)
 item(tt(vi-backward-word) (unbound) (b) (unbound))(
 Move to the beginning of the previous word, vi-style.
 )
+tindex(vi-backward-word-end)
+item(tt(vi-backward-word-end) (unbound) (unbound) (unbound))(
+Move to the end of the previous word, vi-style.
+)
 tindex(beginning-of-line)
 item(tt(beginning-of-line) (^A) (unbound) (unbound))(
 Move to the beginning of the line.  If already at the beginning
diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list
index 36c46d2..39c81e6 100644
--- a/Src/Zle/iwidgets.list
+++ b/Src/Zle/iwidgets.list
@@ -122,6 +122,8 @@
 "vi-backward-delete-char", vibackwarddeletechar, ZLE_KEEPSUFFIX
 "vi-backward-kill-word", vibackwardkillword, ZLE_KEEPSUFFIX
 "vi-backward-word", vibackwardword, 0
+"vi-backward-word-end", vibackwardwordend, 0
+"vi-backward-blank-word-end", vibackwardblankwordend, 0
 "vi-beginning-of-line", vibeginningofline, 0
 "vi-caps-lock-panic", vicapslockpanic, ZLE_LASTCOL
 "vi-change", vichange, ZLE_LASTCOL
diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
index e59304e..301b18d 100644
--- a/Src/Zle/zle_word.c
+++ b/Src/Zle/zle_word.c
@@ -148,8 +148,13 @@ viforwardblankwordend(UNUSED(char **args))
 {
     int n = zmult;
 
-    if (n < 0)
-	return 1;
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardblankwordend(args);
+	zmult = n;
+	return ret;
+    }
     while (n--) {
 	while (zlecs != zlell) {
 	    int pos = zlecs;
@@ -180,7 +185,7 @@ viforwardwordend(char **args)
     if (n < 0) {
 	int ret;
 	zmult = -n;
-	ret = backwardword(args);
+	ret = vibackwardwordend(args);
 	zmult = n;
 	return ret;
     }
@@ -336,6 +341,62 @@ vibackwardblankword(char **args)
 
 /**/
 int
+vibackwardwordend(char **args)
+{
+    int n = zmult;
+
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardwordend(args);
+	zmult = n;
+	return ret;
+    }
+    while (n-- && zlecs > 1) {
+	int start = 0;
+	if (Z_vialnum(zleline[zlecs]))
+	    start = 1;
+	else if (!ZC_iblank(zleline[zlecs]))
+	    start = 2;
+	DECCS();
+	while (zlecs) {
+	    int same = (start != 1) && ZC_iblank(zleline[zlecs]);
+	    if (start)
+		same |= Z_vialnum(zleline[zlecs]);
+	    if (same == (start == 2))
+		break;
+	    DECCS();
+	}
+	while (zlecs && ZC_iblank(zleline[zlecs]))
+	    DECCS();
+    }
+    return 0;
+}
+
+/**/
+int
+vibackwardblankwordend(char **args)
+{
+    int n = zmult;
+
+    if (n < 0) {
+	int ret;
+	zmult = -n;
+	ret = viforwardblankwordend(args);
+	zmult = n;
+	return ret;
+    }
+    while (n--) {
+	while (zlecs && !ZC_iblank(zleline[zlecs]))
+	    DECCS();
+	while (zlecs && ZC_iblank(zleline[zlecs]))
+	    DECCS();
+    }
+    return 0;
+}
+
+/**/
+int
 emacsbackwardword(char **args)
 {
     int n = zmult;



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