[vim/vim] Regex search not matching but 'hlsearch' does match. (Issue #11617)

56 views
Skip to first unread message

JustAnotherSapiens

unread,
Nov 25, 2022, 10:43:39 AM11/25/22
to vim/vim, Subscribed

Steps to reproduce

Characters matching the regex \s\S\n\zs\S are not recognized by the regex \_s\zs\S although they should.
The funny thing is that the 'hlsearch' highlighting actually recognizes them as a valid matches.

To reproduce this:

  1. Copy and paste this sample text in the vim editor:
 1
2
3
4
5 .
6
7
  1. Ensure highlight search is on: set hlsearch
  2. (Optional) For a clear visualization I recommend to execute:
set listchars=eol:~,space:@
set list
  1. Run the search: /\_s\zs\S
  2. Move through the matches in the sample text with n and N and note how neither '2' nor '6' are matched by the regex despite being highlighted.

In general, the unmatched characters follow the pattern \s\S\n\zs\S

This also happens with the search() function.

Expected behaviour

All numbers should be highlighted AND matched by the regex. Thus, being accessible via the n or N commands in normal mode.

Version of Vim

9.0.0916

Environment

OS: Windows 10
This happens on the CMD, PowerShell and on GVIM.

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11617@github.com>

Bram Moolenaar

unread,
Nov 25, 2022, 4:06:29 PM11/25/22
to vim/vim, Subscribed


> ### Steps to reproduce

>
> Characters matching the regex `\s\S\n\zs\S` are not recognized by the regex `\_s\zs\S` although they should.
> The funny thing is that the `'hlsearch'` highlighting actually recognizes them as a valid matches.
>
> To reproduce this:
> 1. Copy and paste this sample text in the vim editor:

> ```
> 1
> 2
> 3
> 4
> 5 .
> 6
> 7
> ```
> 2. Ensure highlight search is on: `set hlsearch`
> 2. (Optional) For a clear visualization I recommend to execute:

> ```
> set listchars=eol:~,space:@
> set list
> ```
> 4. Run the search: `/\_s\zs\S`
> 5. Move through the matches in the sample text with `n` and `N` and note how neither '2' nor '6' are matched by the regex despite being highlighted.

>
> In general, the unmatched characters follow the pattern `\s\S\n\zs\S`
>
> This also happens with the `search()` function.
>
> ### Expected behaviour

>
> All numbers should be highlighted AND matched by the regex. Thus,
> being accessible via the `n` or `N` commands in normal mode.

You need to remove the "c" flag from the 'cpoptions' option to make this
work. See ":help cpo-c" for the explanation.

Still, even then it doesn't work. The search always starts in the first
column. The first match found in "5 ." is then on the space, but the
"\zs" moves the start of the match to the dot. And starting the search
from there skips over the "6".

The fix is to not use the first match start position, but advance just
one character and try for a match there. I hope this doesn't cause a
regresssion.

--
hundred-and-one symptoms of being an internet addict:
144. You eagerly await the update of the "Cool Site of the Day."

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11617/1327885626@github.com>

Bram Moolenaar

unread,
Nov 25, 2022, 4:14:34 PM11/25/22
to vim/vim, Subscribed

Closed #11617 as completed via c96311b.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11617/issue_event/7895178282@github.com>

Reply all
Reply to author
Forward
0 new messages