To include '/' in the search string when doing search & replace, I use
'#' as the field separator ( generally I will not have '#' in my search
strings).
Is there a way to achieve something similar in normal search with '/' or
'?' on the fly?
Regards
Venkat.
If using '/' to search forwards, you would have to escape each slash in the pattern,
that is, put a backslash before each slash. Following command finds "a/b":
/a\/b
Or, if you can select existing text, you can use this tip:
http://vim.wikia.com/wiki/Search_for_visually_selected_text
John
Venkata Suryam wrote:Is there a way to achieve something similar in normal search with '/' or '?' on the fly?If using '/' to search forwards, you would have to escape each slash in the pattern, that is, put a backslash before each slash. Following command finds "a/b": /a\/b
Well, while it's not exactly mis-stream ability to change, you
can so things like
:let @/='some/string/with/slashes?and?question?marks'
which, if you have 'hls' set, you can see readily highlights what
you're looking for. You can then use n/N to go to the
next/previous match.
-tim
It becomes quite annoying to put backslash before each slash especially when I copy & paste the search string on to the command line & the search string has lot of slashes ('/'s).
Thanks a lot. This is what I am looking for.Well, while it's not exactly mis-stream ability to change, you can do things like :let @/='some/string/with/slashes?and?question?marks' which, if you have 'hls' set, you can see readily highlights what you're looking for. You can then use n/N to go to the next/previous match.
you could remap ? and / so that they are prefixed with a backslash:
cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/'
cnoremap <expr> ? getcmdtype() == '?' ? '\?' : '?'
Regards,
Jürgen
--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
Hi, Venkata Suryam Setty ISSA wrote:To include '/' in the search string when doing search & replace, I use '#' as the field separator ( generally I will not have '#' in my search strings). Is there a way to achieve something similar in normal search with '/' or '?' on the fly?you could remap ? and / so that they are prefixed with a backslash: cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/' cnoremap <expr> ? getcmdtype() == '?' ? '\?' : '?'
Venkata Suryam Setty ISSA wrote:
>
yes, both <expr> and getcmdtype() were introduced in VIM 7.0.
The problem with this, even in Vim 7, is that you won't be able to add
an offset after the search, e.g. to go to the line below the match:
/pattern/+1
nor will it work in a range:
:/pattern1/;/pattern2/command
The ":let @/ = expression" solution proposed in the other subthread
looks better to me.
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
145. You e-mail your boss, informing him you'll be late.
On 25/08/08 13:17, Jürgen Krämer wrote:Hi, Venkata Suryam Setty ISSA wrote:To include '/' in the search string when doing search& replace, I use '#' as the field separator ( generally I will not have '#' in my search strings). Is there a way to achieve something similar in normal search with '/' or '?' on the fly?you could remap ? and / so that they are prefixed with a backslash: cnoremap<expr> / getcmdtype() == '/' ? '\/' : '/' cnoremap<expr> ? getcmdtype() == '?' ? '\?' : '?' Regards, JürgenThe problem with this, even in Vim 7, is that you won't be able to add an offset after the search, e.g. to go to the line below the match: /pattern/+1 nor will it work in a range: :/pattern1/;/pattern2/command The ":let @/ = expression" solution proposed in the other subthread looks better to me.
Tony Mechelynck wrote:
> On 25/08/08 13:17, Jürgen Krämer wrote:
>>
>> Venkata Suryam Setty ISSA wrote:
>>> To include '/' in the search string when doing search& replace, I use
>>> '#' as the field separator ( generally I will not have '#' in my search
>>> strings).
>>>
>>> Is there a way to achieve something similar in normal search with '/' or
>>> '?' on the fly?
>> you could remap ? and / so that they are prefixed with a backslash:
>>
>> cnoremap<expr> / getcmdtype() == '/' ? '\/' : '/'
>> cnoremap<expr> ? getcmdtype() == '?' ? '\?' : '?'
>
> The problem with this, even in Vim 7, is that you won't be able to add
> an offset after the search, e.g. to go to the line below the match:
>
> /pattern/+1
>
> nor will it work in a range:
>
> :/pattern1/;/pattern2/command
you can always type <C-V> / or <C-V> ? if you want an unescaped slash or
question mark.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/b23bc7b1-e562-418f-af09-12b9baad3877n%40googlegroups.com.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/38b347c1-6fc2-45c2-b873-3b6eb8a0b9e3n%40googlegroups.com.