:g/^\(.*\)\n\1$/d
:g
: The global (g) command in Vim, performs a certain action on lines that match a given pattern./^
: This symbol denotes the start of a line.\(
and\)
: These parentheses are used for grouping in regex. Everything between\(
and\)
is treated as a single group. This group can be referenced later..*
: The dot (.
) stands for any character except a newline. The asterisk (*
) is a quantifier, meaning "zero or more of the preceding element". So,.*
matches any string, including an empty string.\n
: This represents a newline character.\1
: This is a backreference to the first (and only) group that we defined earlier. In this case, it refers to the exact string that was matched inside the\(
and\)
.$
: This symbol denotes the end of a line./d
: Thed
command deletes the lines that match the given pattern.
In summary, the regular expression :g/^\(.*\)\n\1$/d
performs the following operation:
- It looks for lines in a text that are immediately followed by an identical line.
- If such pairs of identical lines are found, both lines are deleted.
:%sort u