//View Tip #835
Similar Tips
» Sudo from vim to write file
» Making vim oneliners
» Making shell scripts executable via editor hooks


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
A few quick ways to empty a file of text in vi (all of these are done in command mode):


View Comments »


Add your comment

Comments are currently disabled
ggdG I like tihs one
Posted 2009-06-11 12:03:13
faster way



Posted 2009-06-11 12:55:29
:%d  that's the fastest way I know of
Posted 2009-06-11 13:21:18
Hai Vu
Another 4-letter way:
Posted 2009-06-11 15:36:47
Floyd Arguello
I like Jackie's, but here's another way:
cat /dev/null > file
Posted 2009-06-11 16:45:52
Technically, the last one ggdG is a vim thing, and in pure old vi you have to do 1GdG.

But if you are not in vi, then clearing the file with >file is fastest.
Posted 2009-06-12 15:39:38
If you're at the beginning of the file:


of if you aren't:

Posted 2009-07-22 04:09:03

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit