我正在寻找一个 vim 命令,它将匹配并删除包含 4 个或更多单词的所有行,其中单词由分隔符(在本例中为空格字符)分隔。
之前
one two three four five
one two three four
one two three
之后
one two three
最佳答案
awk 来救援!
awk 'NF < 4' foo.txt > output.txt
使用 Vim 的过滤器,:!
,命令(参见 :h :range!
):
:%!awk 'NF < 4'
或者使用 :global
命令和 :delete
的纯 Vim(参见 :h :g
和 :h :d
):
:g/\s.*\s.*\s/d_
关于vim 删除所有包含 X 个或更多单词的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50766469/