7

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
  • Welcome to AskUbuntu, in my opinion O'reilly series, learning vi editor, sed&awk and mastering regular expressions, these books are fantastic. But I need to read 'bash script' books to integrate all the information built in a sense. 'Linux and the Unix Philosophy by Mike Gancarz' helps this a lot. Mar 20 '20 at 1:52
  • There's an online game called VIM Adventures. It seems quite nice, it's free for the first couple of levels. I never tried it myself, but I've seen a few good reviews about it
    – Dan
    Mar 20 '20 at 7:16
  • 1
    Note there's also vi.stackexchange.com
    – stackzebra
    Mar 20 '20 at 8:56
  • Regarding learning the basics of Vim, you can use the vimtutor. You can get to it through the command prompt for Ubuntu, you can just type, vimtutor, and this is a short 30 minute set of lessons to learn the basics of Vim. Mar 20 '20 at 16:16
15

Just open first.txt and run the command:

:w second.txt
2
  • 1
    will you please suggest me any book or kind of to learn,i am using Ubuntu from last 3-4 month and found don't learn any thing. Mar 19 '20 at 22:14
  • 4
    @atharvamishra Go step by step. For vim, you can just start with the command vimtutor, as the name indicates, it's a tutor for vim, in vim. For linux... is too broad to point to something particular. Start with basic commands in the terminal, using the man pages and/or the help: man <command> or <command> --help. You can refer also to https://www.gnu.org/software/bash/manual/. Mar 19 '20 at 22:24
3

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

:!cp "%" second.txt
1
  • Thanks @Warren Young to suggest me another good approach. Mar 20 '20 at 17:59
0

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.