Create new file and open it in new buffer from within vim

Viewed 30

It's baffling how hard it is to find the magical command that does it.

I'm in vim. All I want to do is create a new file and immediately switch to a new buffer with it. How do I do it?

1 Answers

In the first page of the help (:help), see under 'basic editing' the chapter called 'editing.txt' and in that chapter, section 2 'Editing a file'. You can go straight there with :help edit-a-file. You will find the following options (among others):

:edit <your_new_file> will open a new buffer called 'your_new_file' (or open that file if it already exists). Or even shorter :e <your_new_file>.

Or:

:enew will create a new buffer for you to edit. (N.B. Then you can use :saveas <your_new_file> to save it).

I would recommend going over the all the basic editing pages (as well as doing vimtutor) if you're new to vim. The sheer number of help pages might seem overwhelming, but getting comfortable with the basics in vim should 'only' take a few weeks of practice. It's all up from there :)

Related