12

I am currently editing one file and, after finishing its edit, I want to close the current file and at the same time (i.e., without closing Vim) open another file for editing.

How it can be achieved?

7
  • 3
    Use :e filename (or :we filename if you also want to write the previous file) ? (Or maybe I'm misunderstanding you)
    – Feffe
    Jun 6, 2016 at 15:58
  • 2
    I don't think that it will close previous file. It will be in buffer. :buffers will show you.
    – WitVault
    Jun 6, 2016 at 15:59
  • 1
    You're probably right. Would this help you ? stackoverflow.com/questions/1269648/…
    – Feffe
    Jun 6, 2016 at 16:02
  • 3
    You can simply use :bd to close the current buffer and :e filename to open a new one.
    – statox
    Jun 6, 2016 at 16:05
  • 2
    Is the file being open in a buffer important? I mean, you CAN wipe the buffer, but it will get wiped when you close vim.
    – Tumbler41
    Jun 6, 2016 at 16:06

1 Answer 1

13

I don't think this can be done using a single command. You'll have to use a combination of commands:

  1. As statox suggested, delete the current buffer and open a new one:

    :bd | e filename
    
  2. Or rename the current file and edit it:

    :file filename | e
    

Use :w | bd | e filename or :w | file filename | e to save the current file and start on a new one.

You can, of course, use maps or custom commands to simplify this:

:command -nargs=+ WE w | bd | e <args>

Then do:

:WE new-filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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