gpt4 book ai didi

VIM——我可以使用全局命令来过滤两种不同的条件吗?

转载 作者:行者123 更新时间:2023-12-04 00:54:29 26 4
gpt4 key购买 nike

我有一个看起来像这样的文件:

    'description': 'US RTS'
'sgv:activationStatus': true
'sgv:assignedSegments': ['segments:16c...
'sgv:created': 2019-09-25T12:31:36.088-04:00
'sgv:createdBy': '203796'
'sgv:lastModified': 2020-08-11T15:19:39.230-04:00
...

我想删除所有包含“sgv:”的行,除了那些还包含“assignedSegments”的行。我可以这样做:

:g!/assignedSegments/s/sgv:.*/& DELETE/
:g/DELETE/d

但我认为可能有一种更优雅的方式在单行代码中完成。有什么建议吗?

最佳答案

这似乎是你想要的:

:g/sgv:/v/assignedSegments/d

来自 help :g

                                                                E147
When the command is used recursively, it only works on one line. Giving a
range is then not allowed. This is useful to find all lines that match a
pattern and do not match another pattern:
:g/found/v/notfound/{cmd}
This first finds all lines containing "found", but only executes {cmd} when
there is no match for "notfound".

关于VIM——我可以使用全局命令来过滤两种不同的条件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63672565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com