如何解决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
...
我想删除所有包含“ 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".
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。