Introduction to Vim
Summary: in this tutorial, you will learn discover what vim is, why it's worth learning, and how it differs from other text editors through its powerful modal editing paradigm.
Introduction to Vim
If you've ever opened a terminal (that black or dark window where you type commands) and needed to edit a text file, chances are you've heard of Vim. It might seem intimidating at first, but don't worry — this tutorial will walk you through everything step by step, assuming no prior experience.
What you'll learn in this tutorial:
- What Vim is and what a "text editor" means
- Why Vim is worth learning, even if you've never programmed before
- How Vim's unique "modal editing" works (we'll explain what that means!)
- How to open Vim, type some text, save a file, and exit
What Is a Text Editor?
Before we talk about Vim, let's make sure we understand what a text editor is. A text editor is simply a program that lets you create and modify plain text files — things like notes, code, configuration files, and more.
You might already be familiar with text editors like Notepad (on Windows), TextEdit (on Mac), or even more advanced ones like VS Code. Vim is another text editor, but it works differently from all of those.
What Is Vim?
Vim stands for "Vi IMproved." It's a free, open-source text editor that runs inside your terminal (also called the command line — that text-based interface where you type commands instead of clicking buttons).
Vim was originally released by Bram Moolenaar in 1991 as an improvement to an older editor called vi (created by Bill Joy in 1976). Today, Vim is:
- Pre-installed on nearly every Linux and macOS computer — it's already there waiting for you
- Lightweight — it runs in the terminal, so it doesn't need a graphical window with buttons and menus
- Highly configurable — you can customize almost everything about how it looks and works
- Keyboard-driven — you control everything with your keyboard, without ever needing to touch the mouse
What's a terminal? A terminal (also called "command line" or "shell") is a text-based interface for your computer. Instead of clicking icons and menus, you type commands. On Windows, you can find it by searching for "PowerShell" or "Command Prompt." On Mac, search for "Terminal." On Linux, it's usually called "Terminal" too.
Why Learn Vim?
You might be wondering: "Why learn this old-looking editor when there are modern tools like VS Code?" Great question. Here are the main reasons:
Speed
Vim uses a unique approach called modal editing (more on this below). Once you get comfortable with it, you can edit text much faster than in a regular editor because your fingers never leave the keyboard — no reaching for the mouse, no awkward key combinations.
It's Everywhere
If you ever connect to a remote server (for example, a cloud computer running Linux), Vim is almost always already installed. You don't need to download or install anything — it's just there. This makes it incredibly useful for anyone working with servers.
What's a server? A server is a computer (usually located somewhere else) that provides services, like hosting a website. You connect to it remotely using a command called ssh, and when you get there, Vim is usually the only text editor available.
Ergonomics (Comfortable to Use)
Vim keeps your fingers on the center of the keyboard (called the "home row"). Instead of complicated shortcuts like Ctrl+Shift+Alt+Arrow, you use simple single keys like dw (delete a word) or 3j (move down 3 lines). This is easier on your hands over long editing sessions.
It Lasts Forever
Vim has been around for over 30 years, and the skills you learn today will still be useful decades from now. Many modern editors (like VS Code, JetBrains IDEs, and Sublime Text) even offer "Vim mode" plugins because Vim's editing style is that popular.
You don't have to use Vim as your main editor. Many developers use Vim keybindings inside VS Code or other editors, getting the best of both worlds. Learning Vim's editing style is valuable regardless of what tool you end up using day to day.
Vim vs Vi — What's the Difference?
You might see people mention both "vi" and "Vim." Here's the simple explanation:
- vi is the original editor from 1976 — very basic
- Vim is "Vi IMproved" — it adds many modern features on top of vi
| Feature | vi (original) | Vim (improved) |
|---|---|---|
| Syntax highlighting (colored code) | ❌ No | ✅ Yes |
| Undo levels | Only 1 | Unlimited |
| Split windows (view two files at once) | ❌ No | ✅ Yes |
| Visual mode (select text visually) | ❌ No | ✅ Yes |
| Plugins (add-on features) | ❌ No | ✅ Yes |
| Built-in help system | Minimal | Extensive |
On most modern computers, even if you type vi, it actually opens Vim. So don't worry about the difference — just know that Vim is the better, modern version.
The Modal Editing Concept (The Key Idea)
This is the most important concept in Vim, and it's what makes Vim different from every other text editor you've used.
In a regular text editor (like Notepad or VS Code), there's only one mode: you type, and text appears on screen. Simple.
Vim has multiple modes. Think of it like the gears in a car:
- First gear is for one thing (going slow)
- Second gear is for another (going faster)
- You shift between gears depending on what you need
In Vim, you shift between modes depending on what you're doing. Here are the four main modes:
Normal Mode (the Default)
When you first open Vim, you're in Normal mode. This is the mode you'll spend the most time in. In this mode, the keys on your keyboard are commands, not text. For example:
- Pressing
hmoves the cursor left (it does NOT type the letter "h") - Pressing
jmoves the cursor down - Pressing
dddeletes an entire line - Pressing
uundoes your last action
Think of Normal mode as "control mode" — you're controlling the editor, not typing text.
Insert Mode (for Typing Text)
Press i to enter Insert mode. NOW the keys on your keyboard type text, just like any normal editor. You'll see -- INSERT -- appear at the bottom of the screen to confirm you're in Insert mode. When you're done typing, press the Escape key to go back to Normal mode.
Visual Mode (for Selecting Text)
Press v to enter Visual mode. This lets you select (highlight) text by moving the cursor. Once you've selected text, you can delete it, copy it, indent it, and more. Press Escape to return to Normal mode.
Command-Line Mode (for Running Commands)
Press : (colon) to enter Command-line mode. A prompt appears at the bottom of the screen where you can type commands like:
:w— save the file (short for "write"):q— quit Vim:wq— save and quit:help— open Vim's built-in help system
The single most important thing to remember: When you're confused or stuck in Vim, press the Escape key. This always brings you back to Normal mode, which is the "safe" mode where you can figure out what to do next.
Your First Vim Session (Step by Step)
Let's actually use Vim! Follow these steps exactly:
Step 1: Open your terminal and type this command, then press Enter:
vim hello.txtThis opens Vim and creates a new file called hello.txt. You'll see a mostly empty screen with ~ symbols on the left side — these just mean "empty line, no text here yet."
Step 2: Enter Insert mode by pressing the i key. You should see -- INSERT -- appear at the bottom of the screen. This confirms you can now type text.
Step 3: Type some text. Type: Hello, Vim! This is my first file.
Step 4: Return to Normal mode by pressing the Escape key. The -- INSERT -- text at the bottom should disappear.
Step 5: Save and quit by typing :wq and pressing Enter. That's colon, then w, then q, then Enter. This stands for "write" (save) and "quit" (close).
Step 6: Verify your file was saved. Back in your terminal, type:
cat hello.txtYou should see: Hello, Vim! This is my first file.
Congratulations — you just created and saved a file using Vim!
What does cat do? The cat command is a simple terminal command that displays the contents of a file on your screen. It's a quick way to check what's inside a file without opening it in an editor.
How to Exit Vim
There's a famous joke in the programming world: "How do you generate a random string? Put a first-year computer science student in front of Vim and tell them to save and exit."
It might sound silly, but exiting Vim can genuinely confuse beginners because pressing the X button or Ctrl+Q doesn't work. Here's your complete guide:
| What You Type | What It Does |
|---|---|
:q then Enter | Quit Vim (only works if you haven't made unsaved changes) |
:q! then Enter | Quit without saving — discards any changes you made |
:w then Enter | Save the file but don't quit |
:wq then Enter | Save the file AND quit |
ZZ (in Normal mode) | A shortcut to save and quit (same as :wq) |
ZQ (in Normal mode) | A shortcut to quit without saving (same as :q!) |
Remember: You must be in Normal mode to use these commands. If you see -- INSERT -- at the bottom of your screen, press Escape first, then type the command.
Vim's Philosophy
Vim is built around a few core principles that make it powerful. You don't need to master these now — just keep them in mind as you learn:
- Composability — Vim commands combine like building blocks. The
dkey means "delete" andwmeans "word", sodwmeans "delete a word." Once you learn the building blocks, you can combine them in thousands of ways. - Repeatability — The
.key (a single period) repeats whatever you just did. Make one edit, then press.to apply that same edit again and again. - Text objects — Vim understands the structure of text: words, sentences, paragraphs, and blocks enclosed by quotes or brackets. You can operate on these "chunks" rather than individual characters.
- Minimalism — Vim starts fast, runs light, and stays out of your way. It's designed to help you edit efficiently without unnecessary distractions.
Summary
Let's review what you've learned:
- A text editor is a program for creating and modifying text files
- Vim (Vi IMproved) is a keyboard-driven text editor that runs in the terminal
- Vim uses modal editing — different modes for different tasks
- Normal mode (the default) is for navigating and running commands — keys are commands, not text
- Insert mode (press
i) is for typing text — keys produce text like a normal editor - Visual mode (press
v) is for selecting text - Command-line mode (press
:) is for running colon commands like:wq - Press Escape to always return to Normal mode when you're confused
:wqsaves your file and quits Vim- Vim is available on virtually every computer and the skills transfer to other editors
In the next tutorial, you'll install Vim on your computer and set it up with comfortable default settings.
Practice: First Vim Session
Try this on your own to build confidence:
- Open a terminal and run
vim practice.txt - Press
ito enter Insert mode (you should see-- INSERT --at the bottom) - Type three lines of text — anything you like (press Enter between lines)
- Press Escape to return to Normal mode
- Type
:wqand press Enter to save and quit - Run
cat practice.txtto verify your file was saved correctly
Bonus challenge: Open the file again with vim practice.txt, press dd to delete the first line, then press u to undo the deletion (the line comes back!). Exit with :q! to quit without saving your changes.
Show Solution
# Step 1: Open Vim and create a new file
vim practice.txt
# Step 2: Press the i key to enter Insert mode
# You should see -- INSERT -- at the bottom of the screen
# Step 3: Type three lines (press Enter between each line)
# Line one
# Line two
# Line three
# Step 4: Press the Escape key to return to Normal mode
# Step 5: Type :wq and press Enter to save and quit
# Step 6: Check your file was saved
cat practice.txt
# You should see:
# Line one
# Line two
# Line three
# Bonus: Open the file again and try deleting + undoing
vim practice.txt
# Press dd — the first line ("Line one") disappears
# Press u — the line comes back! (undo)
# Type :q! and press Enter to quit without savingWritten by the ShellRAG Team
The ShellRAG editorial team writes practical, beginner-friendly Vim tutorials with tested code examples and real-world use cases. Every article is technically reviewed for accuracy and updated regularly.
Learn more about us →