I have myfile.txt
with some text. If I type vim myfile.txt
it opens the file. Is there some parameter for vim to delete the old file and create an empty new one? For example
vim -recreate myfile.txt
Or is such functionality not supported?
Not really. You could do something like this; a compound command line instruction:
> myfile.txt && vim myfile.txt
The > myfile.txt
would wipe the contents of the file—but leave the actual file in place—and the &&
then ties that command to vim myfile.txt
.
To wipe file you may use:
$ vim +%d +w file
But that’s not a recreation (removing file and creating new one), a file remains the same (same inode
). I guess, there is no difference for you, right?
If I’m wrong and you need a new file, I’m afraid, you have to use shell and rm
:
$ rm file && vim +w file
dG
- this deletes from the cursor position to the end of the file, actually emptying it. If your vim is configured to put the cursor to where it was the last time you edited the file, instead of the first row, prepend1G
to get to the first line.1GdG
is still less to type than-recreate
.