Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you open a file from within Vim?

Tags:

vim

vi

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.

like image 833
jshock Avatar asked May 15 '14 14:05

jshock


People also ask

How do I open a file inside vim?

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.

How do I open a new file in vim editor without exit from that?

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.

How do I view files in vi?

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.


1 Answers

: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.

like image 151
sashang Avatar answered Oct 01 '22 10:10

sashang