The vim “delete all lines” command

vim FAQ: How do I delete all lines in the current text file in vim?

To delete all lines in vim, use this command:

:1,$d

This vim “delete all lines” command can be read like this:

  • The : character starts vim’s “last line mode.”
  • The 1 means, “starting at line 1”
  • The ,$ means, “until the end of the file”
  • The d means, “delete”

After typing the d, you need to hit the [enter] key, and when you do so, all lines in the file will be deleted.

If you needed to see how to delete all lines in a file using vim, I hope this is helpful.