How to Delete All Lines of a File in Vim

You can delete a line in Vim with dd i.e. pressing the d key twice. But what if you want to delete all the lines in Vim.

You cannot do CtrlA and use Del key like you do in a regular text editor. Thataposs not how Vim works.

There is no straightforward keyboard shortcut for this. However you can use the dG keys if you are at the beginning of the file.

Here are the steps.

In short EscggdG is what you need to do for deleting all the lines of the file in Vim.

So how does this dG command works To be precise the d is for the cut action and G is for moving the cursor to the end of the file. This way dG cuts all the text from the current cursor position to the end of the file.

...

Read Full Post

News Link: https://linuxhandbook.com/delete-all-lines-vim/.

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.