Vim global命令使每行包含一个符号,以一个单词开头
考虑以下文本文件:Vim global命令使每行包含一个符号,以一个单词开头,vim,global,Vim,Global,考虑以下文本文件: something something something = someother thing other thing = third thing another thing = forth thing 我想让它看起来像这样: something something keyword something = someother thing keyword other thing = third thing keyword another thing = forth thing
something
something
something = someother thing
other thing = third thing
another thing = forth thing
我想让它看起来像这样:
something
something
keyword something = someother thing
keyword other thing = third thing
keyword another thing = forth thing
所以,我在每行中添加关键字,其中包含一个等号。
我可以使用全局命令执行此操作吗,或者您建议我如何执行此操作
:g/=/s/^/keyword /
:g/=/s/^/关键字/
或
:g/=/normal ikeyword
注意“关键字”后面的空格
对于这类问题,使用以下解决方案也很常见:
:%!sed '/=/s/^/keyword /'
:%!sed'/=/s/^/keyword/'
我不太清楚你想完成什么。你的标题暗示了一个共同的模式,但我在你的例子中没有看到。我给你们两个看 以共同的模式在事物之间进行改变 您可以执行搜索并替换为以下内容:
:s/<regex you are searching for>/<string to replace with>/g
something
的s
上。在插入模式外按
-v
进入可视模式`a
。所有三行的所有三个起始字符都应高亮显示A
追加,或按I
直接进入插入模式并开始键入。当您点击escape时,您的更改应该反映出来!您还可以执行其他命令,如y
和d
等我要找的正是威廉·珀塞尔的建议。该命令在文件中包含等于符号的每一行中插入一个关键字。
:s/<regex you are searching for>/<string to replace with>/g
something = someother thing
other thing = third thing
another thing = fourth thing