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

tim*_*lck 3 vim

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

    '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
...
Run Code Online (Sandbox Code Playgroud)

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

:g!/assignedSegments/s/sgv:.*/& DELETE/
:g/DELETE/d
Run Code Online (Sandbox Code Playgroud)

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

Wil*_*ell 6

这似乎是你想要的:

:g/sgv:/v/assignedSegments/d
Run Code Online (Sandbox Code Playgroud)

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".
Run Code Online (Sandbox Code Playgroud)