Good day.
I started to use zsh recently, and so far I have been enjoying it
greatly. One thing I would like to have is the ability to change the
prompt when doing a history search in vi editing mode.
o I find it confusing that pressing '/' displays a '?' as a prompt
when doing a search (and viceversa). I understand the logic behind
this, but I would still prefer to be able to opt out of it. I have
tried implementing a custom zle widget to work around it, but
reading from the terminal has been causing me issues. It also seems
like a search called through zle doesn't update LASTSEARCH, so
I cannot get the search string either.
o I would like to be able to erase the prompt to exit search mode in
vi. I know that it may be frustrating for some people to
accidentally erase the prompt when trying to do a search, but
that's the way it is in other vi-inspired programs including vi
itself. I'm used to cancelling my searchs this way.
I implemented a patch that makes these two changes under an option I
arbitrarily decided to name "BASH_VI_SEARCH" because I couldn't think
of any better name at the time. If you think the way I did it is not
appropriate, then I am open to suggestions. If you are not interested
in implementing these changes (it's admittedly a very small nitpick),
then that's fine too.
Thank you very much.
======================================================================
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index cbd3d0f8e..aaec9d7a0 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -2538,6 +2538,17 @@ cindex(enabling the beep)
item(tt(BEEP) (tt(PLUS()B)) <D>)(
Beep on error in ZLE.
)
+pindex(BASH_VI_SEARCH)
+pindex(NO_BASH_VI_SEARCH)
+pindex(BASHVISEARCH)
+pindex(NOBASHVISEARCH)
+item(tt(BASH_VI_SEARCH))(
+Use the same prompting style as Bash when searching through history in
+vi mode. That is, when searching backward with this option set, a
+slash will be shown as the prompt for the search. When searching
+forward, a question mark will be shown instead. The default is the
+reverse. This also allows to erase the prompt to cancel the search.
+)
pindex(COMBINING_CHARS)
pindex(NO_COMBINING_CHARS)
pindex(COMBININGCHARS)
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index cfaa70dae..89b82d3d0 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -1811,7 +1811,11 @@ getvisrchstr(void)
}
clearlist = 1;
statusline = sbuf;
- sbuf[0] = (visrchsense == -1) ? '?' : '/';
+ if (isset(BASHVISEARCH)) {
+ sbuf[0] = (visrchsense == -1) ? '/' : '?';
+ } else {
+ sbuf[0] = (visrchsense == -1) ? '?' : '/';
+ }
selectkeymap("main", 1);
while (sptr) {
sbuf[sptr] = '_';
@@ -1841,6 +1845,10 @@ getvisrchstr(void)
sptr = 0;
} else if(cmd == Th(z_backwarddeletechar) ||
cmd == Th(z_vibackwarddeletechar)) {
+ if(isset(BASHVISEARCH) && sptr == 1) {
+ ret = 0;
+ break;
+ }
sptr = backwardmetafiedchar(sbuf+1, sbuf+sptr, NULL) - sbuf;
} else if(cmd == Th(z_backwardkillword) ||
cmd == Th(z_vibackwardkillword)) {
diff --git a/Src/options.c b/Src/options.c
index a994b563e..d203669d4 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -99,6 +99,7 @@ static struct optname optns[] = {
{{NULL, "bareglobqual", OPT_EMULATE|OPT_ZSH}, BAREGLOBQUAL},
{{NULL, "bashautolist", 0}, BASHAUTOLIST},
{{NULL, "bashrematch", 0}, BASHREMATCH},
+{{NULL, "bashvisearch", 0}, BASHVISEARCH},
{{NULL, "beep", OPT_ALL}, BEEP},
{{NULL, "bgnice", OPT_EMULATE|OPT_NONBOURNE},BGNICE},
{{NULL, "braceccl", OPT_EMULATE}, BRACECCL},
diff --git a/Src/zsh.h b/Src/zsh.h
index a0243e98e..8145b300c 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2381,6 +2381,7 @@ enum {
BAREGLOBQUAL,
BASHAUTOLIST,
BASHREMATCH,
+ BASHVISEARCH,
BEEP,
BGNICE,
BRACECCL,
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 533e08773..804302c77 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -12,6 +12,7 @@
# AUTO_RESUME
# BANG_HIST
# BASH_AUTO_LIST
+# BASH_VI_SEARCH
# BEEP (!)
# BG_NICE
# CHECK_JOBS
|