Unique-ify lines in Vim
If I want to get rid of duplicate lines in a text file, in Linux I can simply pipe it through uniq. Windows doesn't have an equivalent (or else I don't know about it). There may be a Vim equivalent also, but I don't know it if there is. Instead you can use perldo to do it like this:
:perldo BEGIN{%x={}} $_ = ' ' if $x{$_}++
The neat thing about perldo (and rubydo) is that whatever you do is persistent across runs of perldo. That means if you run this:
:perldo $_ = ' ' if $x{$_}++
it'll work the first time you run it, but the second time, $x will have retained its values from the first run, and it will instead delete every line. There are few limits to what you can do with a one-liner perldo command in Vim. It's great, if you know Perl better than you know Vim.
EDIT TWO YEARS LATER: How about :sort u.

Speak your Mind
Preview