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, 2020 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, 2020 at 7:16
  • 1
    Note there's also vi.stackexchange.com
    – stackzebra
    Mar 20, 2020 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, 2020 at 16:16

4 Answers 4

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, 2020 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, 2020 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, 2020 at 17:59
0

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

0

open new file

:o newfile.txt

read from old file:

:r oldfile.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .