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