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

后端 未结 4 985
抹茶落季
抹茶落季 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 03:03

    simpler:

    %s/.*/"&"

    Explanation: By default, a pattern is interpreted as the largest possible match, so .* is interpreted as the whole line, with no need for ^ and $. And while \(...\) can be useful in selecting a part of a pattern, it is not needed for the whole pattern, which is represented by & in the substitution. And the final / in a search or substitution is not needed unless something else follows; though leaving it out could be considered laziness. (If so, I'm lazy.)

提交回复
热议问题