UNIX 上 vi 编辑器中的简单问题
我怎样才能添加一些文字,如“ABC” 在 vi 编辑器中所有行的开头? 这不行!
%s/^/^ABC
我知道这个命令用于替换文本
%s/vggv/uggv/g
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您想要:
这会将 ABC 放在每一行的前面。
不要忘记前面的
:
You want:
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:
:%s/^/ABC/
不适合您吗?Doesn't
:%s/^/ABC/
work for you?正如其他人所说,
:%s/^/ABC
就可以了。考虑一下^
的含义。它是一个逻辑结构,而不是文件中的实际字符。因此,您并没有真正替换它,因此不必使用^ABC
。事实上,正如您所见,^
在该上下文中被视为字符串。如果您想跳过仅包含空格的行,可以使用
:v/^[:space:]*$/s/^/ABC
。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
.这将在 vi 编辑器中的每一行前面添加 ABC
this will add ABC in front of every line in vi editor