我有一个看起来像这样的文件:
'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)
但我认为在单行中可能有一种更优雅的方式。有什么建议?
这似乎是你想要的:
: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)
| 归档时间: |
|
| 查看次数: |
27 次 |
| 最近记录: |