How to delete all lines of file in Vim

Updated post here: https://codeyarns.github.io/tech/2011-04-18-how-to-delete-all-lines-of-file-in-vim.html

22 thoughts on “How to delete all lines of file in Vim

    1. Answering my own question: You have to use :%d _
      So you specify the register after the command, separated with a space. See the relevant section in the help file:
      :h :delete

      Like

    1. Antrix: That was a very comprehensive reply for that SO question! 🙂

      Since most of my work happens in Visual Studio, Vim is relegated to be the text editor for “everything else”. Hence I have tended to stick with the vi/vim commands that I am familiar with and have not really probed much into its ex commands, which I realize I need to.

      Like

  1. it is also possible of doing this:

    type following:

    :0,$d

    this will delete all lines from beginning to end of file

    Like

  2. How about just: echo 0 > filename. U will be left with one line of “0” in it. I bet U can do this to true > filename or just: > filename

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.