Vim's command to create a new file with the same content of any other file

Say, there is a file first.txt and I want to make a new file second.txt with the same content of first.txt, is there a direct command in Vim to do that?

I don't want to first create second.txt and then copy the content of first.txt.

4

3 Answers

Just open first.txt and run the command:

:w second.txt
2

Although the straightforward simple answer has already been posted, I offer a fun and instructive alternative:

:!cp "%" second.txt
1

Alternatively, open the first file, then do :saveas second.txt.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like