Easy way to delete all lines of file by using VI / VIM editor – Unix / Linux /MAC

Sometime it might difficult for beginner to delete single or multi line of a file while editing in VI/VIM editor.

Also I have seen peoples who are very new to unix/linux or MAC system they use “delete” key with INSERT Mode to delete single line But its too much time consuming. Even I have seen few of expert teammate use “dd” key to delete each and every line to empty the file.

But there is a very easy approach I have to delete all the lines of a file in VI/VIM editor for Unix / Linux /MAC users.I have mentioned approach below.

Steps to delete all lines in VI/VIM editor:

Step 1 : Open Editor with example file
==> sudo vi file.php

Step 2 : Open editor in command mode by pressing ESC key on the keyboard.

Step 3 : Press “gg” key to reach first line of file.

Step 4 : Then press “dG”. This will delete all lines from the first line to the last line.

See how simple approach it is to remove all the lines in a file.Thanks to visit us.