file
:e
Edit (open) a file in the current window. With no argument, :e reloads the current file from disk — handy after external changes.
:e [filename] (command mode) Variations
| Keystroke | Effect |
|---|---|
| :e! | Reload current file, discarding unsaved edits |
| :e# | Switch to the alternate (previous) buffer — same as pressing <C-^> |
| :find name | Open a file searched from 'path' setting |
| :Ex or :Explore | Open netrw file browser in current window |
Examples
:e src/app.js Open src/app.js in this window
:e Reload current file from disk
:e! Discard changes and reload from disk
Gotcha
:e will refuse if the current buffer has unsaved changes; either save with :w first or force with :e!.
Related
:w / :saveas
Write (save) the current buffer to disk. Without an argument :w saves to the current file; with an argument it writes a copy without switching buffers. Use :saveas when you want to rename the buffer to the new file and keep editing that one.
:vsplit / :split / :tabnew
:split (or :sp) opens a horizontal split, :vsplit (:vsp) a vertical split, :tabnew a new tab page. All three optionally take a filename to open in the new pane/tab.
Ctrl-W
Ctrl-W is the prefix for every window-management command. Follow it with h/j/k/l to move between splits, with =/_/| to resize, or with c/o to close windows.
:q / :q!
:q closes the current window (or exits Vim if it's the last one); :q! quits and DISCARDS unsaved changes. If you're the 'how do I exit Vim' meme — this is the answer.
:wq / ZZ
Write the buffer to disk and quit the window. ZZ (normal mode, two capital Zs) does the same thing without leaving the keyboard's home row — with the subtle difference that ZZ only writes if the buffer actually changed.