Open, Save, Quit
Start here: choose an editor, open a file, make a change, save it, and get out
Start from nothing. Install Neovim or enable Vim controls in your current editor, then open a file, type, move, select, delete, copy, save, and quit.
Start here. This section assumes that you have never opened Vim and do not know what its modes are. You do not need a configuration, a plugin manager, or a new terminal. By the end, you will be able to do enough ordinary editing to leave Vim controls turned on all day. You will be slow. That is fine. Speed comes later.
Choose where to use Vim
The simplest standalone route is a terminal and Neovim, the modern editor used throughout this book. But learning Vim does not require abandoning the editor you already know. VS Code, Visual Studio, and JetBrains IDEs all have good Vim emulators. Start where you already work; the editing language travels with you.
| Where you work | What to install or enable |
|---|---|
| Linux, including Ubuntu under WSL | Try vi --version or vim --version first; one is commonly already installed. Otherwise install Neovim with your package manager. |
| macOS Terminal | Try vi --version first; macOS includes a vi-compatible editor. For modern Neovim, install Homebrew and run brew install neovim. |
| Windows Terminal or PowerShell | Windows itself does not normally include Vim. Run winget install Neovim.Neovim, or install WSL and use the Linux editor inside it. |
| Traditional Vim | Use the Vim downloads page. Vim is completely suitable for everything in this book. |
| VS Code | VSCodeVim for easy setup; VSCode Neovim to use real Neovim as the editing engine |
| Visual Studio | VsVim, a mature Vim emulator whose core is written in F# |
| JetBrains IDEs | IdeaVim |
In VS Code, open the Extensions view, search for VSCodeVim, and select Install. In Visual Studio, open Extensions โ Manage Extensions and search for VsVim. In a JetBrains IDE, open Settings โ Plugins, search for IdeaVim, and select Install. Restart the editor if it asks. Then open any disposable text file and continue with "Your first edit" below.
What may already be installed
Do not install anything until you check. Run nvim --version, vim --version, and vi --version, in that order. If one prints a version banner, you already have an editor with which to begin. Full Linux installations and Linux distributions under WSL commonly include vi or Vim; minimal containers may not. macOS includes a vi-compatible editor. Native Windows normally requires Neovim, Vim, WSL, or an editor extension.
If only vi is available, use it for this first session. Install Neovim when convenient. On macOS with Homebrew, run brew install neovim. On Windows, run winget install Neovim.Neovim. On Ubuntu, Debian, or Ubuntu under WSL, run sudo apt install neovim. Other distributions use their normal package managers. The official Neovim installation page has current commands and direct downloads.
Opening a file
| Key | Note |
|---|---|
| @nvimhello.txt | |
| Enter |
Open a terminal, move to a directory in which you can create a file, and run nvim hello.txt. If you are using Vim or the built-in Unix editor, use vim hello.txt or vi hello.txt instead. If the file exists, you see its contents. If it does not, you see an empty buffer that will be saved as hello.txt the first time you write. Vim does not create the file on disk until you save.
Your first edit
Vim opens in normal mode, where letter keys issue commands instead of inserting text. Press i once to enter insert mode. Type Hello from Vim! just as you would in any editor. Then press Esc to return to normal mode.
Now try the four movement keys: h moves left, j moves down, k moves up, and l moves right. Arrow keys work too. For this first minute, use whichever keys let you stay oriented.
Save and return to the shell
Press Esc to make sure you are in normal mode. Type :wq, then press Enter. The colon opens Vim's command line, w writes the file, and q quits the editor. Back at the shell, run cat hello.txt to confirm that your line reached the disk.
That was a complete Vim session. Everything below gives you separate commands for saving, quitting, and recovering when Vim refuses to exit.
The Minimum for Your First Day
You do not have to learn the whole keyboard before using Vim for real work. For your first day, remember one loop: press i to type, press Esc when you finish typing, move somewhere else, and press i again. Save with :w. Leave with :x. If anything feels wrong, press Esc and begin the loop again.
| Goal | What to do today |
|---|---|
| Type text | Press i, type normally, then press Esc. |
| Move | Use the arrow keys, or begin trying h, j, k, and l. |
| Delete one character | In normal mode, press x. |
| Undo | In normal mode, press u. |
| Save | Type :w, then press Enter. |
| Save and leave | Type :x, then press Enter. |
Arrow Keys Are Allowed
The arrow keys work in Vim. Use them while you are learning. Reaching for them is slower than keeping your hand on hjkl, but being temporarily slow is better than being lost. Begin substituting h, j, k, and l when you remember. Do not disable the arrows or punish yourself for using them. The home-row motions will take over naturally as the rest of the grammar becomes familiar.
Select First, Act Second -- for Now
If you are used to selecting text before cutting or copying it, Vim lets you work that way. Press Esc to enter normal mode, move to the start of some text, and press v to enter visual mode. Move with the arrows or hjkl; Vim highlights the selection. Then press d to delete it, which also saves it for pasting, or press y to copy it without deleting it. Press p to put the saved text after the cursor. Press u if the result is wrong.
The First-Week Bargain
If your work allows it, leave Vim controls enabled for ordinary editing this week. Keep the arrow keys. Keep using the mouse when you need it. Keep a familiar editor around for emergencies. The only commitment is to perform routine edits with the small set above instead of turning Vim off whenever you slow down.
Expect to be slower for weeks and uneven for months. Vim becomes fast by replacing conscious key recall with muscle memory, and muscle memory cannot be rushed. The immediate goal is not speed. It is reaching the point at which you can finish a normal day without escaping back to a different editing model.
Saving
| Key | Note |
|---|---|
| : | |
| w | |
| Enter |
:w "writes" โ Vim's word for save. :w {filename} writes to a different filename (Save As). :w! forces a write through read-only flags.
:wQuitting
| Key | Note |
|---|---|
| : | |
| q | |
| Enter |
:q quits โ if the buffer is clean. If there are unsaved changes, Vim refuses and tells you to save or force-quit. Force-quit with :q! discards changes and exits.
Save and quit
| Command | Behavior |
|---|---|
:wq |
Write, then quit. Always writes (even if nothing changed). |
:x |
Write if changed, then quit. Quieter than :wq. |
| ZZ | Same as :x โ write-if-changed, then quit. Normal-mode shortcut. |
:wq, :x, ZZQuit without saving
| Command | Behavior |
|---|---|
:q! |
Discard changes and quit. |
| ZQ | Same โ Normal-mode shortcut. |
Reference
| Goal | Command |
|---|---|
| Open a file | nvim file from the shell |
| Save | :w |
| Save as | :w new-name |
| Save (force, e.g. read-only) | :w! |
| Quit (clean buffer) | :q or :qa for all |
| Save then quit (always writes) | :wq |
| Save then quit (only if changed) | :x or ZZ |
| Quit, discarding changes | :q! or ZQ |
| Reload from disk (lose changes) | :e! |
Worked example โ :w and :q
Save and quit from the Ex prompt.
Status loses [+]; the file is on disk. :q would now leave Vim.
See also: Insert and Back Again, Undo and Redo, File Operations, Buffers