Is there a built-in way to make Vim open a new buffer with file?
I want open a file. :enew doesn't take any arguments and opens a blank buffer.
:edit closes my existing buffer.
Related (about :enew):
Is there a built-in way to make Vim open a new buffer with file?
I want open a file. :enew doesn't take any arguments and opens a blank buffer.
:edit closes my existing buffer.
Related (about :enew):
I think you might be misunderstanding what you're seeing happen. :edit does not close your current buffer. It just replaces it in the current window. If you type :buffers your previous buffer should still be listed. It is still open and in Vim's memory. The only way to make them go away is to run :bd or :bw (or :q of course).
So, to answer your question: :e newfile.txt
Your previous buffer is now the alternate file to the current buffer (:help alternate-file). You can switch back to it using ctrl-^ or ctrl-6.
There are commands similar to :edit
:split - horizontal split:vsplit - vertical splitBoth of these commands (shortened :sp and :vs respectively) take an optional file argument like :edit does. So, if you wanted to vertically split and create a new file in one command, you would type: :vs newfile.txt
Give :help edit-intro a read to get an idea of how Vim handles files, and :help windows-intro to read up on windows, buffers, and tabs.
I can accomplish the behavior using this, but it's kinda annoying to have to do a few extra keystrokes:
:enew " shorthand: ene
:edit <file> " shorthand: e
" Shorthand to do both
:ene|e <file>
:h new: "This behaves like a ":split" first, and then an ":enew" command." – Jun 21 '16 at 14:57