Reputation: 67299
how could i add some text like 'ABC' at the beginning of all the lines in vi editor? this doesnot work!
%s/^/^ABC
i know this command is used for replacing text
%s/vggv/uggv/g
Upvotes: 0
Views: 446
Reputation: 2289
As others have said, :%s/^/ABC
will do the trick. Consider what ^
means. It is a logical construct, not an actual character in the file. Therefore, you're not really replacing it, so you don't have to use ^ABC
. In fact, as you've seen, ^
is treated as a string in that context.
If you wanted to skip lines that only contain whitespace, you could use :v/^[:space:]*$/s/^/ABC
.
Upvotes: 1
Reputation: 2738
I really love the normal command for things like these:
:%normal IABC
Upvotes: 8
Reputation: 12215
You want:
:%s/^/ABC/g
That will put ABC in front of every line.
Don't forget the :
in front
Upvotes: 8