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?
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.)