Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: https://stackoverflow.com/q/1573361/3258851)
-
Control+F
-
Toggle "Replace mode"
-
Toggle "Use Regular Expression" (the icon with the
.*
symbol) -
In the search field, type
^(.*)(\n\1)+$
-
In the "replace with" field, type
$1
In this case, either resort to a solution outside VS Code (see here), or - if your document is not very large and you don't mind spamming the Replace All button - follow the previous steps, but in steps 4 and 5, enter these:
(based on https://stackoverflow.com/q/48722064/3258851)
Caution: Blocks for files with too many lines (1000+); may cause VS Code to crash; may introduce blank lines in some cases.
-
search:
((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s]*?)^\2$(?:\n)?
-
replace with:
$1
and then click the "Replace All" button as many times as there are duplicate occurrences.
You'll know it's enough when the line count stops decreasing when you click the button. Navigate to the last line of the document to keep an eye on that.
https://stackoverflow.com/questions/37992493/how-to-remove-duplicate-lines-in-visual-studio-code