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.