//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):

:1,$d
--
:1[enter]dG
--
ggdG


View Comments »




Comments 

Add your comment

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

-----

>file

-----
Posted 2009-06-11 12:55:29
Eric
:%d  that's the fastest way I know of
Posted 2009-06-11 13:21:18
Hai Vu
Another 4-letter way:
1GdG
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
Mario
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
mike
If you're at the beginning of the file:

---
d]]
---

of if you aren't:

---
[[d]]
---
Posted 2009-07-22 04:09:03

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit