2

I have two lists like these below:

abc.domain.com defg.domain.com hijklmn.domain.com 
abc.domain.com/sub/ defg.domain.com/anothersub/ hijklmn.domain.com/thirdsub/ 

I need to make these two lists appear like so:

abc.domain.com?ref=abc defg.domain.com?ref=defg hijklmn.domain.com?ref=hijklmn 
abc.domain.com/sub/?ref=sub defg.domain.com/anothersub/?ref=anothersub hijklmn.domain.com/thirdsub/?ref=thirdsub 

How to I accomplish this in vi/vim?

1 Answer 1

6

Assume the two lists are in two different buffers. We can do the job using vim's :s command:

For list1:

%s/\v([^.]+).*/&?ref=\1/ 

For list2:

%s#\v.*/([^/]+)/$#&?ref=\1# 

If the two lists are mixed in one buffer, you can use :g command to do the substitution only on a certain target.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.