INTRODUCTION
Learning Vim
Chapter 1 — Introduction
Why Vim?
Vim is a text editor unlike any other. Most editors behave the way you expect — you open a file, click where you want to type, and start editing. Vim does not work that way, and that difference is exactly what makes it powerful. Once you have learned Vim's way of thinking, you can edit text faster, more precisely, and with less hand movement than in almost any other editor.
Here is what makes Vim worth the investment:
- It is everywhere. Vim — or its predecessor
vi— comes pre-installed on virtually every Unix-based system. Linux servers, macOS, embedded devices, cloud VMs: if you can SSH into it, Vim is almost certainly available. You will never be stranded without an editor. - It runs in a terminal. You do not need a graphical interface. This is critical when working on remote servers, in containers, or in recovery environments where a GUI simply does not exist.
- It is fast. Opening, editing, and closing a file in Vim takes seconds. For quick configuration file edits — the kind of task you do dozens of times a day as a developer or sysadmin — this adds up to a significant amount of saved time.
- It is composable. Vim commands combine like building blocks. Once you understand the grammar — operator + motion — you can do things you have never explicitly learned just by combining parts you already know.
- It is enduring. Vim was released in 1991, built on the ideas of
vifrom 1976. After more than 30 years it is still actively developed and widely used. This kind of longevity (sometimes called the Lindy effect — the longer something has survived, the longer it is likely to continue surviving) is a strong signal that the time you invest in learning it will pay off for the rest of your career.
The Learning Curve — An Honest Picture
Vim has a well-earned reputation for a steep learning curve. A common joke in developer circles is that Vim's learning curve is not just steep but vertical — you put a lot of effort in before you get any results out. That is partially true, but it is more nuanced than the joke suggests.
A better analogy is learning to drive a manual (stick-shift) car:
- The first time you sit behind the wheel, every action is conscious and effortful. You have to think about the clutch, the gear, the mirror, the steering — all at once.
- You will stall. You will forget which gear you are in. The car will do things you did not expect.
- After a few weeks of practice, the conscious effort fades. You change gear without thinking about it. Your hands know what to do before your brain has finished forming the instruction.
- At that point, you are more in control of the car than you ever were when it was automatic — because you understand what it is doing and why.
Vim follows the same arc. The awkward phase is real but it is finite. Most people find that after one to two weeks of daily use (even just 20–30 minutes a day), the basic movements and editing commands start to feel natural. After a month, they start to miss Vim when they are forced to use something else.
The trick is to not abandon Vim during the awkward phase. It helps to have a project or file you actually need to edit — real motivation to push through the discomfort. This course is designed to get you through that phase as efficiently as possible by focusing on the commands you will use every day, explained in a way that makes the underlying logic visible.
Vim's Modal Design — A First Look
The most important thing to understand about Vim before you even open it is that it is a modal editor. This is the idea behind all of Vim's apparent strangeness, and once you understand it everything else clicks into place.
Most editors have one mode: you are always typing text. Vim has several modes, and the meaning of every key you press depends on which mode you are currently in. The three you will use most are:
| Mode | What it is for | How to enter it |
|---|---|---|
| NORMAL | Navigating, deleting, copying, and issuing commands. This is Vim's home base — the mode you should return to when you are not actively inserting text. | Press Esc from any other mode |
| INSERT | Typing text into the file, just like a conventional editor. | Press i in Normal mode |
| COMMAND | Running editor commands — saving, quitting, searching, changing settings. | Press : in Normal mode |
The reason most people get stuck when they first open Vim is that they are dropped straight into Normal mode. They start typing, and nothing appears (or unexpected things happen) because keystrokes in Normal mode are commands, not text. This single piece of knowledge — Vim starts in Normal mode — eliminates the most common source of confusion.
We will explore each mode thoroughly in the chapters ahead. For now, just hold onto this mental model: Normal mode is your home; Insert mode is where you type; Command mode is where you talk to the editor.
Installation
Checking whether Vim is already installed
On macOS and most Linux distributions, Vim is pre-installed. Open a terminal and run:
vim --version
If Vim is installed you will see several lines of output beginning with the version number:
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled ...)
Included patches: 1-749
...
The first line tells you the version. Vim 8 or 9 is recommended — both support all the features in this course. If you see command not found, follow the installation steps below.
vi — the original editor that Vim is based on. Running vi --version on such a system often actually invokes Vim in compatibility mode. For this course, always use vim explicitly to ensure you have the full feature set.
macOS
macOS ships with Vim, but it may be an older version. To install the latest:
# Using Homebrew (recommended) brew install vim # Verify the new version is on your PATH which vim # should show /usr/local/bin/vim or /opt/homebrew/bin/vim vim --version
Linux
Use your distribution's package manager:
# Debian / Ubuntu sudo apt update && sudo apt install vim # Fedora / RHEL / CentOS sudo dnf install vim # Arch Linux sudo pacman -S vim # Alpine (common in Docker containers) apk add vim
Windows
Vim is not pre-installed on Windows. Download the official installer from www.vim.org:
- Go to vim.org → Download → PC, MS-DOS and MS-Windows
- Download the latest gvim_X.Y.exe installer (this installs both the terminal
vimand the GUIgvim) - Run the installer with default options
- Open a new Command Prompt or PowerShell window and run
vim --versionto verify
wsl --install in an elevated PowerShell), then install Vim inside your Linux distribution as described above.
Opening Vim & the Interface
Starting Vim
To open an existing file:
vim filename.txt
To create a new file:
vim newfile.txt
To open Vim with no file (you can name the file when saving):
vim
Reading the interface
When Vim opens a new empty file you will see something like this:
~
~
~
~
~
~
0,0-1 All
Each ~ represents a line that does not exist — it is Vim telling you "there is no content here". The status bar at the bottom right shows your position in the file: 0,0-1 means line 0 (no lines yet), column 0. All means the entire file is visible on screen.
When you open an existing file the content fills the screen and the status bar shows the filename and line/column position:
This is the first line of my file
This is the second line
~
~
"myfile.txt" 2 lines, 58 characters
Enabling line numbers
Line numbers make navigation much easier — you can jump directly to a specific line, and error messages from compilers and interpreters almost always refer to line numbers. To enable them, switch to Command mode and run:
:set number
Type the colon (:) first — this moves you from Normal mode into Command mode and you will see the cursor jump to the bottom of the screen. Then type set number and press Enter. Line numbers will appear on the left of every line.
1 This is the first line of my file
2 This is the second line
3 ~
4 ~
To turn line numbers off:
:set nonumber
This setting only lasts for the current session. In Chapter 8 we will cover the .vimrc configuration file, where you can make it permanent with a single line.
:set relativenumber.
Your First Vim Session — A Safe Walkthrough
Before we go any further, here is a simple sequence you can follow right now to open Vim, make a small edit, and get out safely. Think of it as a first driving lesson in a car park.
# 1. Open a new test file vim test.txt
Vim opens in NORMAL mode. The screen is empty (or shows the file contents). Nothing you type will appear as text yet.
- Press
i— this enters INSERT mode. You will see-- INSERT --at the bottom of the screen. - Type a few words:
Hello from Vim! - Press
Esc— this returns you to NORMAL mode. The-- INSERT --indicator disappears. - Type
:wand pressEnter— this saves (writes) the file. - Type
:qand pressEnter— this quits Vim.
Congratulations — you have successfully entered, edited, saved, and exited Vim. These five steps cover the most common stumbling block new users face.
:q! — the exclamation mark forces Vim to quit and discard any unsaved changes. This is your escape hatch whenever something has gone wrong and you just want out.