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.
Open Vim with any file or just Vim: $ vim file1. Type the contents of file and get into command mode (Press Esc ) :tabedit file2 , will open a new tab and take you to edit file2. :tabedit file3 , will open a new tab and take you to edit file3.
If you're already in vim, then there's no need to exit it just to open a new file. That will open the file for editing. You can also use the tab-key for autocompletion of the path. Please note that the current file must be saved, or you've to use :e! to discard the unsaved changes.
To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.
: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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With