Replace Only First Occurence after PatternHow to replace patterns after line kRepeat replace one character...

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms (Python)

Confusion regarding control system of Mars Rover?

Meaning of "fin" in "fin dai tempi"

Why aren't faces sharp in my f/1.8 portraits even though I'm carefully using center-point autofocus?

Why do personal finance apps focus on outgoings rather than income

Caro-Kann c4-c5 push

Lighthouse Alternatives

The answer is a girl's name (my future granddaughter) - can anyone help?

GPLv3 forces us to make code available, but to who?

Why the first octet of a MAC address always end with a binary 0?

Why such a singular place for bird watching?

How do my husband and I get over our fear of having another difficult baby?

Missing quartile in boxplot

How to level a picture frame hung on a single nail?

Is it possible to do this kind of wavy texture procedurally?

Bothered by watching coworkers slacking off

Does the US Armed Forces refuse to recruit anyone with an IQ less than 83?

Did Tolkien ever write about a Heaven or Hell for Men?

If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?

Can anyone give me the reason why music is taught this way?

SOQL injection vulnerability issue

Does Bank Manager's discretion still exist in Mortgage Lending

Do jackscrews suffer from blowdown?

Can the President of the US limit First Amendment rights?



Replace Only First Occurence after Pattern


How to replace patterns after line kRepeat replace one character (r) for next occurenceChange/delete matching brackets at the same timeReplace a pattern with current line numberUse pattern of global ex command found on a line to substitute in another lineHow do I replace only the current instance of the search pattern without losing the pattern?Sub replace if whole line match patternSearch for line, move to end of search string, then search+replaceFind and replace only between searched patternsReplace after a specific pattern






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








1















Suppose I have a file which contains:



TEMP=100
TEMP=100


and I want to change all of the string beyond 'TEMP=' to 200, so it would read:



TEMP=200
TEMP=200


I could use the command :%s/TEMP=zs.*/200/



What is the command I need to ensure that only the first instance gets changed? The result should read:



 TEMP=200
TEMP=100


I have tried :s/TEMP=zs.*/200/ but this fails unless I first perform :%s/TEMP=zs.*/200/.



Many thanks!










share|improve this question







New contributor



Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    1















    Suppose I have a file which contains:



    TEMP=100
    TEMP=100


    and I want to change all of the string beyond 'TEMP=' to 200, so it would read:



    TEMP=200
    TEMP=200


    I could use the command :%s/TEMP=zs.*/200/



    What is the command I need to ensure that only the first instance gets changed? The result should read:



     TEMP=200
    TEMP=100


    I have tried :s/TEMP=zs.*/200/ but this fails unless I first perform :%s/TEMP=zs.*/200/.



    Many thanks!










    share|improve this question







    New contributor



    Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      1












      1








      1








      Suppose I have a file which contains:



      TEMP=100
      TEMP=100


      and I want to change all of the string beyond 'TEMP=' to 200, so it would read:



      TEMP=200
      TEMP=200


      I could use the command :%s/TEMP=zs.*/200/



      What is the command I need to ensure that only the first instance gets changed? The result should read:



       TEMP=200
      TEMP=100


      I have tried :s/TEMP=zs.*/200/ but this fails unless I first perform :%s/TEMP=zs.*/200/.



      Many thanks!










      share|improve this question







      New contributor



      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Suppose I have a file which contains:



      TEMP=100
      TEMP=100


      and I want to change all of the string beyond 'TEMP=' to 200, so it would read:



      TEMP=200
      TEMP=200


      I could use the command :%s/TEMP=zs.*/200/



      What is the command I need to ensure that only the first instance gets changed? The result should read:



       TEMP=200
      TEMP=100


      I have tried :s/TEMP=zs.*/200/ but this fails unless I first perform :%s/TEMP=zs.*/200/.



      Many thanks!







      replace find






      share|improve this question







      New contributor



      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 9 hours ago









      Jack RolphJack Rolph

      253 bronze badges




      253 bronze badges




      New contributor



      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Jack Rolph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          1 Answer
          1






          active

          oldest

          votes


















          4
















          That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you can also specify marks or even specify search items.



          For the search you can specify the full range of regular expressions that vim knows about and you can even add offsets to it.



          So for your use case, you want to replace from the first line until the search term TEMP is found, so you can use:



          1,/^TEMP=/s/TEMP=zs.*/200/


          which will perform the :s command only between the first line and the first line found that starts with TEMP=.



          For the details see :h :range and for a regular expression introduction have a look at :h 27.4 in the user manual.






          share|improve this answer



























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "599"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });







            Jack Rolph is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded
















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f21297%2freplace-only-first-occurence-after-pattern%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4
















            That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you can also specify marks or even specify search items.



            For the search you can specify the full range of regular expressions that vim knows about and you can even add offsets to it.



            So for your use case, you want to replace from the first line until the search term TEMP is found, so you can use:



            1,/^TEMP=/s/TEMP=zs.*/200/


            which will perform the :s command only between the first line and the first line found that starts with TEMP=.



            For the details see :h :range and for a regular expression introduction have a look at :h 27.4 in the user manual.






            share|improve this answer






























              4
















              That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you can also specify marks or even specify search items.



              For the search you can specify the full range of regular expressions that vim knows about and you can even add offsets to it.



              So for your use case, you want to replace from the first line until the search term TEMP is found, so you can use:



              1,/^TEMP=/s/TEMP=zs.*/200/


              which will perform the :s command only between the first line and the first line found that starts with TEMP=.



              For the details see :h :range and for a regular expression introduction have a look at :h 27.4 in the user manual.






              share|improve this answer




























                4














                4










                4









                That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you can also specify marks or even specify search items.



                For the search you can specify the full range of regular expressions that vim knows about and you can even add offsets to it.



                So for your use case, you want to replace from the first line until the search term TEMP is found, so you can use:



                1,/^TEMP=/s/TEMP=zs.*/200/


                which will perform the :s command only between the first line and the first line found that starts with TEMP=.



                For the details see :h :range and for a regular expression introduction have a look at :h 27.4 in the user manual.






                share|improve this answer













                That % in the %s command at the beginning of your command specifies a range and tells the command to be run for all lines (short for 1,$, where $ stands for the last line). Besides line numbers, you can also specify marks or even specify search items.



                For the search you can specify the full range of regular expressions that vim knows about and you can even add offsets to it.



                So for your use case, you want to replace from the first line until the search term TEMP is found, so you can use:



                1,/^TEMP=/s/TEMP=zs.*/200/


                which will perform the :s command only between the first line and the first line found that starts with TEMP=.



                For the details see :h :range and for a regular expression introduction have a look at :h 27.4 in the user manual.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 8 hours ago









                Christian BrabandtChristian Brabandt

                17.2k28 silver badges49 bronze badges




                17.2k28 silver badges49 bronze badges


























                    Jack Rolph is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded

















                    Jack Rolph is a new contributor. Be nice, and check out our Code of Conduct.













                    Jack Rolph is a new contributor. Be nice, and check out our Code of Conduct.












                    Jack Rolph is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Vi and Vim Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f21297%2freplace-only-first-occurence-after-pattern%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                    The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                    Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...