0

What i would like to do :

Every time i find something based on s[w|l].*[0-9]\.\* replace the end of that string\search .* with %s/\.\*/\\\\\.\.\*/g

Already tried with standard search and replace, but couldn't do it.

Thanks

romainl
  • 186,200
  • 21
  • 280
  • 313
rkpt
  • 39
  • 6
  • 1
    I don't follow. Please clarify and give an example (text and expected replacement). – Ingo Karkat Dec 17 '14 at 12:07
  • I would like to replace the end of this searched srting "slcassdsap01.*" with \\.* – rkpt Dec 17 '14 at 12:10
  • So, turn `slcassdsap01FOO` into `slcassdsap01\FOO`?! – Ingo Karkat Dec 17 '14 at 12:13
  • Turn slcsdtp01.* into slcsdtp01\\.* please remind that i found that by searching /s[w|l].*[0-9].* – rkpt Dec 17 '14 at 12:15
  • doesn't this work for you? `s/\v(blahblah\d+)(.*)/\1\\\\\2/` better in your question give detailed requirement, what should your text look like, before and after. – Kent Dec 17 '14 at 12:19
  • I closed your original attempt because your second answer is better, but still isn't up to standards (as you see by the downvotes). This seems to be a very basic search & replace problem, something that almost any Vim tutorial covers. – Ingo Karkat Dec 17 '14 at 14:55

1 Answers1

0

Just wrap your search pattern in escaped parentheses \(\), and use a backreference \1 in the replacement string:

:%s/\(s[w|l].*[0-9]\)\.\*/\1\\\\.*/g

You can have several \(\) subexpressions in your search string, and can use them both in the search string itself and in the replacement string via \1, \2, ... . Subexpressions are simply numbered by order of occurence in the search string.

cmaster - reinstate monica
  • 38,891
  • 9
  • 62
  • 106