Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: highlighting and cursor for vi-quoted-insert
- X-seq: zsh-workers 55290
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: highlighting and cursor for vi-quoted-insert
- Date: Fri, 20 Nov 2026 02:24:36 +0100
- Archived-at: <https://zsh.org/workers/55290>
- List-id: <zsh-workers.zsh.org>
In line with Ctrl-V in vi, our vi-quoted-insert widget temporarily
displays a ^ character at the cursor position. In vim, this character
gets the same highlighting as control characters (represented as ^A, ^B,
etc) would. In zsh, this is covered by "special" in zle_highlight. In
additon to applying that highlighting to the ^, I think it also makes
sense to apply the "pending" cursor form in this context, having also
done that for the vi-find-next/prev-char widgets (f and t in vi). A
patch follows.
Vim allows you to enter character codes following Ctrl-V. So you can
enter a literal escape with any of ^Vx1b ^V027 ^Vo033 ^Vu001b ^VU1b^[
That's something I only use very occasionally but would probably not be
hard to add if anyone thinks it'd be especially useful to them.
Oliver
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index b29b7fe10..a259167f4 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1363,6 +1363,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish)
initmodifier(&zmod);
prefixflag = 0;
region_active = 0;
+ cursor_special = 0;
/* semantic prompt marker printed before first prompt */
if (*markers)
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index afec9b603..ea1355f0c 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -233,6 +233,13 @@ struct region_highlight *region_highlights;
/**/
int n_region_highlights;
+
+/*
+ * Use special highlighting for the cursor position
+ */
+/**/
+int cursor_special;
+
/*
* Flag that highlighting of the region is active.
*/
@@ -1320,6 +1327,8 @@ zrefresh(void)
} else {
/* Single wide character */
rpms.s->chr = *t;
+ if (cursor_special && t == scs)
+ rpms.s->atr = all_attr;
}
rpms.s++;
while (--width > 0) {
diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 052681661..b4e8bea23 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -155,7 +155,11 @@ vigetkey(void)
ZLE_CHAR_T sav = zleline[zlecs];
zleline[zlecs] = '^';
+ cursor_special = 1;
+ vichgflag = 2;
zrefresh();
+ vichgflag = nochg;
+ cursor_special = 0;
getfullchar(0);
zleline[zlecs] = sav;
if(LASTFULLCHAR == ZLEEOF)
@@ -1108,13 +1112,19 @@ vipoundinsert(UNUSED(char **args))
int
viquotedinsert(char **args)
{
+ int nochg = vichgflag;
#ifndef HAS_TIO
struct sgttyb sob;
#endif
spaceinline(1);
zleline[zlecs] = '^';
+
+ vichgflag = 2;
+ cursor_special = 1;
zrefresh();
+ vichgflag = nochg;
+ cursor_special = 0;
#ifndef HAS_TIO
sob = shttyinfo.sgttyb;
sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author