Vim: insert the same characters across multiple lines

后端 未结 12 1921
慢半拍i
慢半拍i 2020-11-29 14:23

Sometimes I want to edit a certain visual block of text across multiple lines.

For example, I would take a text that looks like this:

name
comment
ph         


        
12条回答
  •  旧时难觅i
    2020-11-29 14:42

    Suppose you have this file:

    something
    
    name
    comment
    phone
    email
    
    something else
    and more ...
    

    You want to add "vendor_" in front of "name", "comment", "phone", and "email", regardless of where they appear in the file.

    :%s/\<\(name\|comment\|phone\|email\)\>/vendor_\1/gc
    

    The c flag will prompt you for confirmation. You can drop that if you don't want the prompt.

提交回复
热议问题