如何在 Vim 的每行末尾添加文本? [英] How to add text at the end of each line in Vim?
本文介绍了如何在 Vim 的每行末尾添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Vim 中,我有以下文本:
In Vim, I have the following text:
key => value1
key => value2
key => value1111
key => value12
key => value1122222
我想在每行的末尾添加,".之前的文字将变成以下内容:
I would like to add "," at the end of each line. The previous text will become the following:
key => value1,
key => value2,
key => value1111,
key => value12,
key => value1122222,
有人知道怎么做吗?是否可以使用视觉块模式来完成此操作?
Does anyone know how to do this? Is it possible to use visual block mode to accomplish this?
推荐答案
这将对文件中的每一行进行:
This will do it to every line in the file:
:%s/$/,/
如果您想执行行的子集而不是整个文件,您可以指定它们来代替 %
.
If you want to do a subset of lines instead of the whole file, you can specify them in place of the %
.
一种方法是进行视觉选择,然后键入 :
.它将为您填写:'<,'>
,然后您输入其余部分(注意您只需要添加s/$/,/
)
One way is to do a visual select and then type the :
. It will fill in :'<,'>
for you, then you type the rest of it (Notice you only need to add s/$/,/
)
:'<,'>s/$/,/
这篇关于如何在 Vim 的每行末尾添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文