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
How to Generate a Git SSH Key on Your Mac and Add it to GitHub
31 Aug 2025
Why Are My React Components Re-rendering Too Much?
26 Jul 2025
How to Use Custom Hooks in React
01 Jun 2025