0

Is there a way to have s;/;|;g run only on the lines I filter using a regex?

I have a file, which looks like:

Date: 2017/08/18
Path /home/share/thing
Path /home/me/thing
Date: 2017/08/18
Path /home/share/thing
Date: 2017/08/18
Path /home/share/thing
Path /home/me/thing
...

Now this is simplified, but the point is I want to substitute the / on the lines beginning with Path, but not the ones beginning with Date. I can grab all of the lines with Path easily enough (:g/Path) and substitute all of the /s (:%s;/;|;g), but for substituting on the specific lines I only know how to give s a range, which doesn't help much.

It seems like it would be easiest if you could pipe the output of g to s, but I couldn't find anything on doing something like that.

2
  • If you don't mind, I will use this question as an example exercise in my plugin EXtend.vim. It just fits perfectly for the purpose of the plugin. Commented Sep 2, 2018 at 0:32
  • @SaulAxelMartinezOrtiz all content on Stack Exchange is licensed under CC BY-SA 3.0, so you can do what you like as long as you provide proper attribution
    – jpyams
    Commented Sep 4, 2018 at 2:09

1 Answer 1

5

You can "pipe" the lines from :g/ to :s. Really, this is a special case of using any command after the g//.

g/Path/s;/;|;g

This is also documented explicitly at the bottom of the section :help :g

1
  • g/^Path/s;/;|;g lines beginning with Path, not lines containing it :) Commented Oct 31, 2017 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.