How to replace a `norm some string ` by `| some string|` quickly? [duplicate]Find and replace strings in vim on multiple linesVim - Capture strings on Search and use on ReplaceHow to match string within parentheses (nested) in Java?How to replace a character by a newline in VimIndent multiple lines quickly in viHow to replace all occurrences of a string in JavaScriptWhat is your most productive shortcut with Vim?How to do case insensitive search in VimHow do I make Git use the editor of my choice for commits?How does the vim “write with sudo” trick work?MySQL string replaceHow do I exit the Vim editor?Move cursor to end of file in vim

Can there be absolute velocity?

What differences exist between adamantine and adamantite in all editions of D&D?

Assigning function to function pointer, const argument correctness?

How durable are silver inlays on a blade?

Confused with atmospheric pressure equals plastic balloon’s inner pressure

Oil draining out shortly after turbo hose detached/broke

How far would a landing Airbus A380 go until it stops with no brakes?

Extracting data from Plot

If there's something that implicates the president why is there then a national security issue? (John Dowd)

Should I put programming books I wrote a few years ago on my resume?

Is it a acceptable way to write a loss function in this form?

How can I remove material from this wood beam?

How can powerful telekinesis avoid violating Newton's 3rd Law?

How to create a cubic equation that include sums of the roots of another cubic equation

C++ logging library

Suppose leased car is totalled: what are financial implications?

I've been given a project I can't complete, what should I do?

Is Lambda Calculus purely syntactic?

How do we say "within a kilometer radius spherically"?

To what extent do precedents in Westminster systems apply in other countries that use it?

How to avoid typing 'git' at the begining of every Git command

Command of files and size

Ability To Change Root User Password (Vulnerability?)

Use 1 9 6 2 in this order to make 75



How to replace a `norm some string ` by `| some string|` quickly? [duplicate]


Find and replace strings in vim on multiple linesVim - Capture strings on Search and use on ReplaceHow to match string within parentheses (nested) in Java?How to replace a character by a newline in VimIndent multiple lines quickly in viHow to replace all occurrences of a string in JavaScriptWhat is your most productive shortcut with Vim?How to do case insensitive search in VimHow do I make Git use the editor of my choice for commits?How does the vim “write with sudo” trick work?MySQL string replaceHow do I exit the Vim editor?Move cursor to end of file in vim






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0
















This question already has an answer here:



  • Find and replace strings in vim on multiple lines

    9 answers



  • Vim - Capture strings on Search and use on Replace

    4 answers



I am editing a markdown file with vim. This file exist many string norm some string . I want to replace them by | some string |. Does there exist any quick way? Thanks very much.



The answer in Find and replace strings in vim on multiple lines can not answer my question. It just talk about general replacing for one line and multi line. Here I want to replace a surrounding and keep the string in the surrounding.










share|improve this question















marked as duplicate by Stephen Kennedy, rene, eyllanesc, Doktor OSwaldo, Pearly Spencer Mar 25 at 18:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • The some string may include some bracket pair .

    – Huayi Wei
    Mar 24 at 21:45

















0
















This question already has an answer here:



  • Find and replace strings in vim on multiple lines

    9 answers



  • Vim - Capture strings on Search and use on Replace

    4 answers



I am editing a markdown file with vim. This file exist many string norm some string . I want to replace them by | some string |. Does there exist any quick way? Thanks very much.



The answer in Find and replace strings in vim on multiple lines can not answer my question. It just talk about general replacing for one line and multi line. Here I want to replace a surrounding and keep the string in the surrounding.










share|improve this question















marked as duplicate by Stephen Kennedy, rene, eyllanesc, Doktor OSwaldo, Pearly Spencer Mar 25 at 18:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • The some string may include some bracket pair .

    – Huayi Wei
    Mar 24 at 21:45













0












0








0









This question already has an answer here:



  • Find and replace strings in vim on multiple lines

    9 answers



  • Vim - Capture strings on Search and use on Replace

    4 answers



I am editing a markdown file with vim. This file exist many string norm some string . I want to replace them by | some string |. Does there exist any quick way? Thanks very much.



The answer in Find and replace strings in vim on multiple lines can not answer my question. It just talk about general replacing for one line and multi line. Here I want to replace a surrounding and keep the string in the surrounding.










share|improve this question

















This question already has an answer here:



  • Find and replace strings in vim on multiple lines

    9 answers



  • Vim - Capture strings on Search and use on Replace

    4 answers



I am editing a markdown file with vim. This file exist many string norm some string . I want to replace them by | some string |. Does there exist any quick way? Thanks very much.



The answer in Find and replace strings in vim on multiple lines can not answer my question. It just talk about general replacing for one line and multi line. Here I want to replace a surrounding and keep the string in the surrounding.





This question already has an answer here:



  • Find and replace strings in vim on multiple lines

    9 answers



  • Vim - Capture strings on Search and use on Replace

    4 answers







vim replace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 21:56







Huayi Wei

















asked Mar 24 at 21:43









Huayi WeiHuayi Wei

3521213




3521213




marked as duplicate by Stephen Kennedy, rene, eyllanesc, Doktor OSwaldo, Pearly Spencer Mar 25 at 18:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Stephen Kennedy, rene, eyllanesc, Doktor OSwaldo, Pearly Spencer Mar 25 at 18:48


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • The some string may include some bracket pair .

    – Huayi Wei
    Mar 24 at 21:45

















  • The some string may include some bracket pair .

    – Huayi Wei
    Mar 24 at 21:45
















The some string may include some bracket pair .

– Huayi Wei
Mar 24 at 21:45





The some string may include some bracket pair .

– Huayi Wei
Mar 24 at 21:45












2 Answers
2






active

oldest

votes


















1














What you're looking for are so-called capture groups and backreferences. Provided there are no nested forms (curly braces inside do not mean a problem in themselves) and forms spanning multiple lines, a quick solution could be: %s/\norm (.*)/\|1\|/g.



The 1 in the substitution part refers to the group captured by (.*), i.e. the original content inside the outermost pair of curly braces. See e.g. http://www.vimregex.com/#backreferences for more.






share|improve this answer

























  • Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

    – Huayi Wei
    Mar 25 at 2:08






  • 1





    @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

    – Stun Brick
    Mar 25 at 8:41






  • 1





    @StunBrick Thanks for your suggestion.

    – Huayi Wei
    Mar 25 at 8:48






  • 1





    @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

    – pamacs
    Mar 25 at 9:29



















0














You could also use a macro to accomplish what you want.



Place your cursor on the first line that have the pattern you want to substitute. Then start recording the macro:



qq0ldwr|$xi|ESCjq


Meaning:



qq = start recording a macro (q) in register q
0 = move to the beginning of the line
l = move one char to the right
dw = delete the word
r| = substitute what is under the cursor with a "|"
$ = move to the end of line
x = delete last char of the line
i = insert mode
| = insert chars "|"
ESC = exit insert mode
j = move to next line
q = stop recording


Execute the macro with:



@q


Execute the macro once again:



@@


Keep doing it for as many lines as needed, or use:



<number>@@
ex. 100@@


To execute the macro number times.






share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    What you're looking for are so-called capture groups and backreferences. Provided there are no nested forms (curly braces inside do not mean a problem in themselves) and forms spanning multiple lines, a quick solution could be: %s/\norm (.*)/\|1\|/g.



    The 1 in the substitution part refers to the group captured by (.*), i.e. the original content inside the outermost pair of curly braces. See e.g. http://www.vimregex.com/#backreferences for more.






    share|improve this answer

























    • Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

      – Huayi Wei
      Mar 25 at 2:08






    • 1





      @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

      – Stun Brick
      Mar 25 at 8:41






    • 1





      @StunBrick Thanks for your suggestion.

      – Huayi Wei
      Mar 25 at 8:48






    • 1





      @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

      – pamacs
      Mar 25 at 9:29
















    1














    What you're looking for are so-called capture groups and backreferences. Provided there are no nested forms (curly braces inside do not mean a problem in themselves) and forms spanning multiple lines, a quick solution could be: %s/\norm (.*)/\|1\|/g.



    The 1 in the substitution part refers to the group captured by (.*), i.e. the original content inside the outermost pair of curly braces. See e.g. http://www.vimregex.com/#backreferences for more.






    share|improve this answer

























    • Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

      – Huayi Wei
      Mar 25 at 2:08






    • 1





      @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

      – Stun Brick
      Mar 25 at 8:41






    • 1





      @StunBrick Thanks for your suggestion.

      – Huayi Wei
      Mar 25 at 8:48






    • 1





      @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

      – pamacs
      Mar 25 at 9:29














    1












    1








    1







    What you're looking for are so-called capture groups and backreferences. Provided there are no nested forms (curly braces inside do not mean a problem in themselves) and forms spanning multiple lines, a quick solution could be: %s/\norm (.*)/\|1\|/g.



    The 1 in the substitution part refers to the group captured by (.*), i.e. the original content inside the outermost pair of curly braces. See e.g. http://www.vimregex.com/#backreferences for more.






    share|improve this answer















    What you're looking for are so-called capture groups and backreferences. Provided there are no nested forms (curly braces inside do not mean a problem in themselves) and forms spanning multiple lines, a quick solution could be: %s/\norm (.*)/\|1\|/g.



    The 1 in the substitution part refers to the group captured by (.*), i.e. the original content inside the outermost pair of curly braces. See e.g. http://www.vimregex.com/#backreferences for more.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 25 at 22:33

























    answered Mar 24 at 23:50









    pamacspamacs

    586




    586












    • Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

      – Huayi Wei
      Mar 25 at 2:08






    • 1





      @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

      – Stun Brick
      Mar 25 at 8:41






    • 1





      @StunBrick Thanks for your suggestion.

      – Huayi Wei
      Mar 25 at 8:48






    • 1





      @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

      – pamacs
      Mar 25 at 9:29


















    • Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

      – Huayi Wei
      Mar 25 at 2:08






    • 1





      @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

      – Stun Brick
      Mar 25 at 8:41






    • 1





      @StunBrick Thanks for your suggestion.

      – Huayi Wei
      Mar 25 at 8:48






    • 1





      @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

      – pamacs
      Mar 25 at 9:29

















    Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

    – Huayi Wei
    Mar 25 at 2:08





    Thanks for your reply. This reply can partially answer my question. There exist some in my case, eg. norm A^-1 .

    – Huayi Wei
    Mar 25 at 2:08




    1




    1





    @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

    – Stun Brick
    Mar 25 at 8:41





    @HuayiWei he's giving you the resources to find what you need to figure out how to do it yourself, he's not going to give you the exact regex.

    – Stun Brick
    Mar 25 at 8:41




    1




    1





    @StunBrick Thanks for your suggestion.

    – Huayi Wei
    Mar 25 at 8:48





    @StunBrick Thanks for your suggestion.

    – Huayi Wei
    Mar 25 at 8:48




    1




    1





    @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

    – pamacs
    Mar 25 at 9:29






    @HuayiWei Sorry, that was a typo, "do not mean a problem" was intended. If yout try it, you can see that it works with your example, and the result will be | A^-1 |. The case which this regex cannot handle is e.g. norm ... norm ... (but you could do multiple rounds :) ). If you have arbitrary levels of nesting, that actually cannot be handled by a simple regex form at all, since you need some form of recursion for that. See for this e.g.: stackoverflow.com/questions/17759004/….

    – pamacs
    Mar 25 at 9:29














    0














    You could also use a macro to accomplish what you want.



    Place your cursor on the first line that have the pattern you want to substitute. Then start recording the macro:



    qq0ldwr|$xi|ESCjq


    Meaning:



    qq = start recording a macro (q) in register q
    0 = move to the beginning of the line
    l = move one char to the right
    dw = delete the word
    r| = substitute what is under the cursor with a "|"
    $ = move to the end of line
    x = delete last char of the line
    i = insert mode
    | = insert chars "|"
    ESC = exit insert mode
    j = move to next line
    q = stop recording


    Execute the macro with:



    @q


    Execute the macro once again:



    @@


    Keep doing it for as many lines as needed, or use:



    <number>@@
    ex. 100@@


    To execute the macro number times.






    share|improve this answer



























      0














      You could also use a macro to accomplish what you want.



      Place your cursor on the first line that have the pattern you want to substitute. Then start recording the macro:



      qq0ldwr|$xi|ESCjq


      Meaning:



      qq = start recording a macro (q) in register q
      0 = move to the beginning of the line
      l = move one char to the right
      dw = delete the word
      r| = substitute what is under the cursor with a "|"
      $ = move to the end of line
      x = delete last char of the line
      i = insert mode
      | = insert chars "|"
      ESC = exit insert mode
      j = move to next line
      q = stop recording


      Execute the macro with:



      @q


      Execute the macro once again:



      @@


      Keep doing it for as many lines as needed, or use:



      <number>@@
      ex. 100@@


      To execute the macro number times.






      share|improve this answer

























        0












        0








        0







        You could also use a macro to accomplish what you want.



        Place your cursor on the first line that have the pattern you want to substitute. Then start recording the macro:



        qq0ldwr|$xi|ESCjq


        Meaning:



        qq = start recording a macro (q) in register q
        0 = move to the beginning of the line
        l = move one char to the right
        dw = delete the word
        r| = substitute what is under the cursor with a "|"
        $ = move to the end of line
        x = delete last char of the line
        i = insert mode
        | = insert chars "|"
        ESC = exit insert mode
        j = move to next line
        q = stop recording


        Execute the macro with:



        @q


        Execute the macro once again:



        @@


        Keep doing it for as many lines as needed, or use:



        <number>@@
        ex. 100@@


        To execute the macro number times.






        share|improve this answer













        You could also use a macro to accomplish what you want.



        Place your cursor on the first line that have the pattern you want to substitute. Then start recording the macro:



        qq0ldwr|$xi|ESCjq


        Meaning:



        qq = start recording a macro (q) in register q
        0 = move to the beginning of the line
        l = move one char to the right
        dw = delete the word
        r| = substitute what is under the cursor with a "|"
        $ = move to the end of line
        x = delete last char of the line
        i = insert mode
        | = insert chars "|"
        ESC = exit insert mode
        j = move to next line
        q = stop recording


        Execute the macro with:



        @q


        Execute the macro once again:



        @@


        Keep doing it for as many lines as needed, or use:



        <number>@@
        ex. 100@@


        To execute the macro number times.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 17:53









        DoktornDoktorn

        54737




        54737













            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript