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?
The two answers suggesting %s
are perfect, and I expect you'll learn to love %s
and use it often. But if you find yourself wanting to surround other blocks of text frequently, you owe it to yourself to check out the surround.vim plugin, which would allow you to do what you asked for with the following four keystrokes: yss"
And there are many other useful built-in surround targets. For example, to surround the current word with double quotes: csw"
, and to change the surrounding single quotes to double quotes: cs'"
.
surround.vim is one of my favorite vim plugins, and I use it daily.