How do you open a file from within Vim?

jshock picture jshock · May 15, 2014 · Viewed 56.6k times · Source

I know how to open a file in Vim from a terminal (vim fileName). What I can't figure out is how to open a file when I'm already within Vim.

I tried :r fileName, but that appears to read (or append) the file into the unsaved buffer I have open. It creates a new file, because when I try to write it with :w, it asks for a filename.

Answer

sashang picture sashang · May 15, 2014

:e <filename>

or

:Ex <directory>

lets you browse for the file from the given directory.

:Ex on its own will open the pwd.

:enew

will create an empty buffer.