VIM -- 我可以使用全局命令来过滤两种不同的条件吗?
VIM -- can I use Global Command to filter on two different conditions?
我有一个如下所示的文件:
'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".
我有一个如下所示的文件:
'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".