The ?/a/b/c solution is really cool.  I have had this question in my mind for
a very long time and I cant believe I could not think of this ultra simple
solution...!

Thanks!


A.J.Mechelynck wrote:
> 
> Tim Chase wrote:
>>>> To search the string say /a/b/c/d/e/f/g/h/i in a file, is there a way 
>>>> to do
>>>> it without going to each / and escaping it to \/
>>>
>>>     :let @/ = escape('string with /slashes/, \backslashes\, .periods., 
>>> *asterisks* etc.', '/\.*')
>>>
>>>     n
>> 
>> 
>> Building on Tony's good suggestion...it's a good one, and an 
>> aircraft-carrier of a solution, swatting many more problems that are 
>> possible to arise, scaling to a full assault on the problem that 
>> consists of arbitrary escaping of any metacharacter.
> 
> Thanks for the compliment, Tim, but don't overdo it, you're making me 
> blush. ;-)
> 
>> 
>> However, if you want to *just* include forward-slashes, you can search 
>> *backwards* for them, and then reverse your direction:
>> 
>>     ?/a/b/c/d/e/f/g/h/i
>>     N
>> 
>> A slightly lazier way to do it with far less typing. :)
>> 
>> Or a hybrid approach:
>> 
>>     :let @/='/a/b/c/d/e/f/g/h/i'
>>     n
>> 
>> Once you've done either my first suggestion, you can use the regular "/" 
>> command and then use control+P to bring up the last 
>> search...magicomysteriously pre-escaped for you. :)  This makes it handy 
>> to reverse the direction/meaning of n/N for future searches.  I'm not 
>> sure why the second variant doesn't get remembered in the search history.
>> 
>> -tim
> 
> In the second variant you don't use a search command (like / ? or :s) 
> but an arithmetic evaluation command. Then n does search, but _it_ 
> doesn't change the latest search pattern. Don't know if the fact that 
> ":let @/" doesn't alter search history must be regarded as a bug, a 
> feature, or a legacy "thing that we don't particularly like but have to 
> live with".
> 
> Your solution is a good one too, and more economical than mine if only / 
> is of concern. For some reason I hadn't realised (or remembered) that 
> you can use unescaped / in a ? search.
> 
> 
> 
> Best regards,
> Tony.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/search-a-b-c-d-e-in-a-file-tf2093687.html#a5772460
Sent from the Vim - General forum at Nabble.com.

Reply via email to