Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:02:49+00:00 2026-06-07T14:02:49+00:00

If I have a file: aaa / new replacement line AAA / old target

  • 0

If I have a file:

aaa / new replacement line
AAA / old target line
random line
random line 
BBB / old target line
CCC / old target line

In this example there are 4 replacements, so the final file should end up like:

aaa / new replacement line
aaa / new replacement line
random line
random line 
aaa / new replacement line
aaa / new replacement line

I have an attempt at an answer below but would like to see your input on this also.
Maybe there is a more successful ‘vim golf’ approach I am unaware of. Maybe I’m just being really dumb and there is a simple command for this.

Basically, the question is this: if I have a line yanked into a register, how do I completely replace searched lines matching ‘old target line’?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:02:52+00:00Added an answer on June 7, 2026 at 2:02 pm

    Use 0y$ to yank your replacement line – this won’t include the newline.

    Then use:

    %s/.*old target line.*/\=@"
    

    To replace the target lines with the contents of the unnamed register, which will contain the last yank.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file with lines like this: AAA,A-name,num1,num2,num3 BBB,B-name,num1,num2,num3 CCC.DDD,C-name,num1,num2,num3 EEE.FFF.GGGG,E-name,num1,num2,num3 HHH.H-name,num1,num2,num3
I have a css file of this type col1 col2 AAA a 1 a1
I have a file with word list, each on new line and in capital
I have a file called one_to_many.txt. In the file is the data: a,aaa b,bbb
I have a json file with contents like this: { aaa:{ status:available, classkey:dotnet },
I have a variable like aaa/bbb/ccc/xxx.html and I need to create the path in
I have a file as follows: line 1: _____ ... # for AAA #export
I have a text file in the format of: aaa: bcd;bcd;bcddd;aaa:bcd;bcd;bcd; Where bcd can
I have an html file in assets, aaa.html. I want to read the contents
Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.