如何删除Vim中的所有非重复行?对于删除重复行有很多解决方案。我想倒着做。我只想留下至少有一个重复的行。
有人知道怎么做吗?
发布于 2014-11-18 08:08:20
:%y yank the whole buffer
:vnew create a new vertical window
Vp paste in place of line 1
:sort sort the buffer
:%!uniq -u remove duplicates
:%s/.*/g\/&\/d turn every line into a :global command that deletes the matching line
:%y yank the whole buffer
:bw! delete that buffer
(and close the window and move back to the original window)
:@" execute the :global commands contained in the unnamed register诚然,这比肯特的回答要多得多,但希望能显示出维姆的多才多艺。
发布于 2014-11-17 21:09:24
如果您在Linux上,请在vim中尝试这一行:
:%!awk 'a[$0]++'如果您正在寻找纯vim/vimscript解决方案,您可以在vim中构建一个字典,键是行文本,值是该行在缓冲区中发生的次数,最后筛选出这些value ==1条目。
阅读:h dict :h filter(的文档
发布于 2014-11-21 08:33:58
我的PatternsOnText插件现在有一个:DeleteUniqueLinesIgnoring命令来执行这个任务。
https://stackoverflow.com/questions/26981192
复制相似问题