我试图想出一些东西,它会从给定角色开始删除所有文本到行尾.
例如,在下面的示例中,我想只保留IP地址:
192.168.2.121/32 -m comment --comment "blah blah bye bye" -j DROP
10.1.3.207 -m comment --comment "much longer comment with all kinds of stuff" -j DROP
172.16.1.0/24 -m comment --comment "Drop this range" -j DROP
Run Code Online (Sandbox Code Playgroud)
要删除的模式是-m,即从左侧读取,遇到第一个" - ".从" - "到行尾应该删除文件中的每一行.
我对这一个感到困惑,指导将不胜感激.
全球指挥将是一个很好的选择
:g/-/norm nD
Run Code Online (Sandbox Code Playgroud)
说明
:g : Start a Global Command (:h :g for extra help on global commands)
/- : Search for -
/norm nD : Execute nD in Normal Mode where
n - jumps to the match
D - delete to the end of the line
Run Code Online (Sandbox Code Playgroud)
在普通模式下有一个简单的方法可以做到这一点:
/-m 让光标移动到文件中第一个出现的“-m”处。d$删除从光标到行尾的字符。n找到另一个“-m”。.重做第 2 步。我会注册一个宏,例如:
0ql开始在信件上注册宏lt-D+q结束宏3@l启动三次的解释t-D+:
t-位于下一次出现的前面-D删除直到结束+, 跳转到字符串开头的下一行,以便我们可以链接宏(l在 vim 上也应该工作,因为你删除到最后)正如 @Nobe4 所说,您还可以在一行上注册宏(例如qlt-Dq),然后在视觉选择上重复:VG:normal!@l。