Both $ and \n represents the end of a line. To remove an empty line we can use either :g/^$/d or :%s/^\n//g

My questions are:

What's the difference between these two signs?

It seems the first command removes a line while the latter one replaces a line by nothing. Hence the first one should be more efficient than the second one. Is my analysis correct?

What about the comparison between :g/^$/d and :g/^\n/d?

1 Answer 1


To put it briefly, $ (and ^) are null-size, empty markers that, when replaced, actually remove nothing (so you basically append to the line), while \n stands for the character (or characters) separating 2 lines: if you replace \n, you will also join those lines.

That's why if you replace your substitute example with %s/^$//g, nothing happens.

The :g/^$/d works because the pattern is only used to find the line, and d (delete) is the one actually removing the line, EOL included (since it is an Ex command).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.