Adding characters at the start and end of each line in a file

后端 未结 4 986
抹茶落季
抹茶落季 2021-01-30 02:32

What is the best way to add some characters at the start and end of each line? Can it be done using Vim, or some other way?

4条回答
  •  面向向阳花
    2021-01-30 02:59

    In vim, you can do

    :%s/^\(.*\)$/"\1"/
    
    • s/regex/replace/ is vim command for search n replace.
    • % makes it apply throughout the file
    • ^ and $ denotes start and end of the line respectively.
    • (.*) captures everything in between. ( and ) needs to be escaped in vim regexes.
    • \1 puts the captured content between two quotes.

提交回复
热议问题