开发者

simple question in vi editor on unix

开发者 https://www.devze.com 2023-03-20 14:55 出处:网络
how could i addsome text like \'ABC\' at the beginning of all the lines in vi e开发者_高级运维ditor?

how could i add some text like 'ABC' at the beginning of all the lines in vi e开发者_高级运维ditor? this doesnot work!

%s/^/^ABC

i know this command is used for replacing text

%s/vggv/uggv/g


You want:

:%s/^/ABC/g

That will put ABC in front of every line.

Don't forget the : in front


I really love the normal command for things like these:

:%normal IABC


Doesn't :%s/^/ABC/ work for you?


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.


:%s/^/ABC/g

this will add ABC in front of every line in vi editor

0

精彩评论

暂无评论...
验证码 换一张
取 消