2

I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.

Questions:

  1. What substitutions are being made, as indicated by the status line?
  2. How do I accomplish what I want to do (eliminate empty lines from a file)?
  • One answer to #2 is :g/^$/d – chb Jun 1 at 1:46
  • A solution would be to replace an actual character: :%s/^\n// but that depends on file format. – aragaer Jun 1 at 10:26
8
  1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters
  2. To actually perform the substitution, the idioms are
:g/^$/d

and

:g/^$/j

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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