Vim is a powerful text editor widely used in the Linux community. Whether you're cleaning up a configuration file or starting fresh with a script, knowing how to delete all content in a file can be useful. In this post, I'll guide you through the steps to quickly remove all text within a file using Vim.
1. Open the File
First, launch your terminal and open the file you wish to edit using Vim:
vim filename
Make sure to replace filename with the name of the file you want to clear.
2. Switch to Normal Mode
If you are not already in Normal mode, press Esc to ensure you're ready to enter commands.
3. Select All Content
Now, you can select all the content in the file by typing the following:
ggVG
gg: Moves the cursor to the beginning of the file.V: Enters Visual Line mode.G: Selects everything from the cursor position to the end of the file.
4. Delete the Selected Content
With everything selected, simply press d to delete the content.
5. Save and Exit
Finally, to save your changes and exit Vim, type the following:
:wq
This command writes your changes (saves the file) and quits Vim.
🔍. Similar posts
Mastering Vue 3 Template Syntax: A Complete Guide
09 Feb 2026
What is Hoisting in JavaScript
08 Feb 2026
What is ECMAScript
08 Feb 2026