Create a file with this in it:
foo/a
foo/b
foo/bar
foo?bar
Do a search by typing "/foo/bar" or "?foo?bar". It will highlight all occurrences of "foo", not just "foo/bar" or "foo?bar".
Note that "/foo?bar" and "?foo/bar" both work.
### Expected behaviour
I would expect the whole string to have been searched for.
I know that this has been a longstanding issue, and many people have posted explanations on how to escape the embedded "/" or "?".
But where in the vim specification does it say the embedded "/" or "?" is not a literal?
I'm doing a search here, not a substitution, so it looks to me like this is just a deficiency in the implementation, likely you're using the same code to process both searches and substitutions, and decomposing the command-string prior to performing the search.
### Version of Vim
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 13 2022 09:35:02) Included patches: 1-3995, 4563, 4646, 4774, 4895, 4899, 4901, 4919 Modified by team...@tracker.debian.org Compiled by team...@tracker.debian.org Huge version without GUI.
### Environment
Ubuntu 22.04
xterm-256color
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
### 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.
Ok looking further, I see that there's an oprional "count" argument allowed:
?foo?2
/foo/2
Could you add an option to disable this?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
And, honestly, why couldn't the syntax have been "2/foo" instead of "/foo/2", which would have allowed for "2/foo/bar" to work?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Based on this posting
https://vim.fandom.com/wiki/Searching_for_expressions_which_include_slashes
I tried re-mapping the '/' in my ~/.vimrc
command! -nargs=1 / let @/ = <q-args>|set hlsearch
but it didn't work.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
IUsing the above, tried to search with the command "/foo/bar" but it gave me the error
E486: Pattern not found: foo\\
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
Ok. And adding this seems to take care of the analogous case with ? search:
:nnoremap ? :call QuestionEscape()<CR>?
:function QuestionEscape()
: cnoremap <CR> <C-\>eescape(getcmdline(), '?')<CR><CR>:cunmap <lt>CR><CR>
:endfunction
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.
Closed #11460 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.