Re: vi - inability to search backwards for ?

2023-05-14 Thread Jeremy Mates
On 2023-05-13 20:53:01 -0700, Kastus Shchuka wrote:
> Have you tried using ?[\?] in extended mode? It works for me.

Yes, that's already in the blog posting and is a bit more to type and remember 
than a ?\?



Re: vi - inability to search backwards for ?

2023-05-13 Thread Kastus Shchuka
On Fri, May 12, 2023 at 11:11:23PM -0700, Jeremy Mates wrote:
> A search for /\/ is okay; this discards the \ and searches for "/"
> 
> A search for ?\? is not okay; this discards the \ and searches for "?"
> which is an invalid regular expression, "RE error: repetition-operator
> operand invalid".
> 
> A problematic bare leading ? on a backwards search can be escaped by
> the following, though I'm not sure if that's an ideal fix. Thoughts?

Have you tried using ?[\?] in extended mode? It works for me.



Re: vi - inability to search backwards for ?

2023-05-13 Thread Jeremy Mates
On 2023-05-13 10:26:42 +0200, Andreas Kusalananda Kähäri wrote:
> I'm assuming this is with the "extended" option set in vi, right?

Yes.



Re: vi - inability to search backwards for ?

2023-05-13 Thread Andreas Kusalananda Kähäri
On Fri, May 12, 2023 at 11:11:23PM -0700, Jeremy Mates wrote:
> A search for /\/ is okay; this discards the \ and searches for "/"
> 
> A search for ?\? is not okay; this discards the \ and searches for "?"
> which is an invalid regular expression, "RE error: repetition-operator
> operand invalid".
> 
> A problematic bare leading ? on a backwards search can be escaped by
> the following, though I'm not sure if that's an ideal fix. Thoughts?
> 
> --- search.c.orig Sat Dec 10 08:06:18 2022
> +++ search.c  Fri May 12 23:05:31 2023
> @@ -120,6 +120,12 @@
>   plen = t - ptrn;
>   }
>  
> + if (delim == '?' && *ptrn == '?') {
> + ptrn--;
> + plen++;
> + *ptrn = '\\';
> + }
> +
>   /* Compile the RE. */
>   if (re_compile(sp, ptrn, plen, >re, >re_len, >re_c,
>   RE_C_SEARCH |

I'm assuming this is with the "extended" option set in vi, right?

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



vi - inability to search backwards for ?

2023-05-13 Thread Jeremy Mates
A search for /\/ is okay; this discards the \ and searches for "/"

A search for ?\? is not okay; this discards the \ and searches for "?"
which is an invalid regular expression, "RE error: repetition-operator
operand invalid".

A problematic bare leading ? on a backwards search can be escaped by
the following, though I'm not sure if that's an ideal fix. Thoughts?

--- search.c.orig   Sat Dec 10 08:06:18 2022
+++ search.cFri May 12 23:05:31 2023
@@ -120,6 +120,12 @@
plen = t - ptrn;
}
 
+   if (delim == '?' && *ptrn == '?') {
+   ptrn--;
+   plen++;
+   *ptrn = '\\';
+   }
+
/* Compile the RE. */
if (re_compile(sp, ptrn, plen, >re, >re_len, >re_c,
RE_C_SEARCH |