📢 Actions Speak Louder Than Words!

VIM - Delete every lines

Posted: Jul 18, 2020 | Reading time: 2 min

It been awhile since my last project (warehouse stock system) in Korea almost 1 years ago, I have been idle because no projects comes in.

Lot of self learning, administration, attend training and etc to kill the time. So this means, I have free time to learn something advance with VIM.

Maybe some of you don’t know what is vim. In short this is text editor on your terminal (unix-terminal) and capable to do lot of thing if you know how to use.

In this episode, I want to share how I deleting every lines on current existing file via vim and it works for me ( Thank to Alvin Alexander for tips ). To delete all lines in vim, insert this command:


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 command, you need to hit the [enter] key, and when you do so, all lines in the file will be deleted.

Well i just re-post the same thing from Alvin Alexander . All creadit goes to him.

For your information, I have 3 trick how to wipe up all lines inside text file. One is what i share above and the other 2 techniques is using pressing gg and then dG but it not always for for every version of vim editor. The last one is nullify the file using cat /dev/null > target_file but this command is dangerous if mistake happen, it much better to use first technique so I will open, view and confirm what inside my text file and nuke it…bomb!.. remove all lines!!!


Discussion and feedback

You can use utterances provided below to post comment on behalf using Github account. Alternatively, you can just send a public comment to my mailing list or send a private message to my e-mail. In a few cases and on certain time, I just don’t have time to moderate them. Please read terms-of-service (ToS) for details.