site news and other musings.

How to Delete All Lines in a File Using Vi or Vim

| Comments

Working with Octopress I tend to do a lot of editing in an offline text editor ( Sublime ) and then copy / pasta the content in my “_post/*.markdown” files.

For a while I ended up deleting the file and recreating it using “cat” but this was a bit cumbersome.

Decided to open up the old Google and dig up how you can do this quicker.

Solution #1
1. Type gg to go back to the start of the file
2. Type dG to delete all lines

Solution #2 ( bit more elegant )
1. Type %d to delete all the things

Hope this helps someone out.