I have an issue regarding editing strings using VIM, I currently have the following strings:
The red fox.
The red fox.
The blue fish.
The blue fish.
Question: how do I remove the duplicates? and lets say that I have a minimum of 500 lines with duplicates
Expected result:
The red fox.
The blue fish.
If you do not need to preserve the order of the lines you can do:
:sort u
i.e. sort all lines and remove duplicates.
If you don't want to sort lines:
:g/^\(.*\)$\n\1/d
Explanation:
:g/^\(.*\)$\n\1/d
g/ /d # Delete the lines matching the regexp
^\(.*\)$ # Match a whole line and put it in substitution register 1
\n\1 # Match substitution register 1 preceded by new line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With