Vim is not just a text editor—it is an entirely different language for editing text. First released in 1991, Vim remains one of the most powerful, ubiquitous, and efficient tools a developer or system administrator can master.
If you have ever found yourself constantly reaching for the mouse to navigate a file, or getting wrist strain from stretching to the arrow keys, learning Vim will completely transform how you work.
In this comprehensive guide, we will walk through everything from installing Vim to understanding its unique “modal” design, basic movements, text manipulation, and finally customizing it to act like a modern IDE.
Why Learn Vim?
With modern, feature-rich editors like VS Code and JetBrains available, why bother learning a terminal-based editor from the 90s?
- Unmatched Speed: Vim is entirely keyboard-driven. By keeping your hands on the home row and eliminating the mouse, your editing speed drastically increases.
- Everywhere You Go: Vim (or its predecessor,
vi) is pre-installed on virtually every Linux, macOS, and Unix system in the world. If you SSH into a remote server, Vim will be there waiting for you. - Ergonomics: Constantly moving your right hand to the mouse or arrow keys causes strain. Vim’s home-row navigation is significantly better for your wrists.
- The Power of the Vim Language: Vim treats editing like speaking. Once you learn the “verbs” (delete, change, yank) and the “nouns” (words, paragraphs, tags), you can perform massive edits with just three keystrokes.
Installation & First Launch
Installing Vim is incredibly simple across all major operating systems.
For Linux (Debian/Ubuntu):
sudo apt update
sudo apt install vim
For macOS:
brew install vim
(macOS comes with a default vi installation, but using Homebrew gives you the latest, full-featured version.)
For Windows:
The best way to use Vim on Windows is through WSL (Windows Subsystem for Linux), where you can simply use the Linux apt command above.
Launching Vim
To open a file (or create a new one), simply type:
vim my-document.txt
The Secret to Vim: Modal Editing
Most modern text editors only have one mode: you press a key, and that letter appears on the screen.
Vim is a modal editor, meaning the keys on your keyboard do different things depending on which “mode” you are currently in.
- Normal Mode: This is the default mode. Here, your keys act as commands to navigate the file, delete text, copy, and paste. You should spend 90% of your time in Normal Mode.
- Insert Mode: This is where you actually type text. Press
ito enter Insert Mode. When you are done typing, immediately pressEscto return to Normal Mode. - Visual Mode: Used for highlighting text. Press
vto enter Visual Mode. - Command Mode: Used for saving files, quitting, and searching. Press
:from Normal Mode to enter Command Mode.
Crucial Rule: If you ever get confused or stuck, aggressively mash the
Esckey a few times. This guarantees you are safely back in Normal Mode.
Basic Movement (Ditch the Arrow Keys)
To move around effectively in Vim, you must stop using the arrow keys. Keep your right hand on the home row and use these four keys in Normal Mode:
h- Move Leftj- Move Downk- Move Upl- Move Right
This feels incredibly unnatural at first, but after a few days, it will become pure muscle memory.
Faster Navigation
Moving one character at a time is slow. Use these shortcuts to fly across the file:
w- Jump forward to the start of the next word.b- Jump backward to the start of the previous word.0(Zero) - Jump to the absolute beginning of the line.$- Jump to the absolute end of the line.gg- Jump to the very top of the file.G- Jump to the very bottom of the file.
The Vim Language: Verbs and Nouns
Vim becomes incredibly powerful when you combine an action (verb) with a movement (noun).
The Verbs
d- Delete (Cut)c- Change (Delete the text and immediately drop you into Insert Mode)y- Yank (Copy)p- Put (Paste)
The Magic Combinations
Let’s combine them! If d is delete, and w is word, what happens if you type dw?
You guessed it: Delete Word.
dd- Deletes the entire current line.d$- Deletes from your cursor to the end of the line.yy- Copies the entire current line.c$- Changes text from the cursor to the end of the line.
”Inside” and “Around”
Vim also understands the structure of your code. You can use i (inside) and a (around) to target specific text blocks.
ciw- Change Inside Word: Instantly deletes the word your cursor is currently on and puts you in Insert Mode.di"- Delete Inside ”: Deletes everything inside the nearest set of double quotes. Absolutely brilliant for editing strings in code!ya(- Yank Around (: Copies everything inside a set of parentheses, including the parentheses themselves.
Saving, Quitting, and Undoing
To interact with the file itself, ensure you are in Normal Mode (Esc), type a colon :, and then type your command:
:w- Write (Save) the file.:q- Quit Vim.:wq- Save and Quit.:q!- Force quit and destroy any unsaved changes.
Made a mistake while editing?
- Press
uin Normal Mode to Undo. - Press
Ctrl + rto Redo.
Searching and Replacing
Searching
To search for a word, press / in Normal Mode, type your word, and hit Enter.
For example: /function
- Press
nto jump to the next match. - Press
Nto jump to the previous match.
Replacing Text
Vim uses a powerful substitution command. To replace the word “apple” with “orange” everywhere in your file, type:
:%s/apple/orange/g
%means the entire file.sstands for substitute.gmeans global (replace all occurrences on a line, not just the first one).
Customizing Vim (.vimrc)
Vim looks incredibly plain out of the box. You can customize its behavior by creating a configuration file located at ~/.vimrc.
Open the file:
vim ~/.vimrc
Here is a great beginner configuration to make Vim look and feel modern. Paste this into the file and save it:
" Show line numbers
set number
" Show relative line numbers (makes jumping easier)
set relativenumber
" Use 4 spaces instead of tabs
set tabstop=4
set shiftwidth=4
set expandtab
" Enable syntax highlighting
syntax on
" Highlight search results
set hlsearch
set incsearch
" Enable mouse support (helpful for beginners!)
set mouse=a
Conclusion: The Learning Curve
Learning Vim is like learning to play an instrument. For the first three days, you will feel incredibly slow, frustrated, and tempted to go back to VS Code.
Push through that barrier.
Force yourself to use Vim for all your configuration file edits and minor scripts. Once your fingers memorize ciw and hjkl, you will never want to edit text any other way.
If you are looking to practice safely, type vimtutor into your terminal right now. It is a built-in, interactive lesson that takes about 30 minutes to complete and is the absolute best way to build your initial muscle memory. Happy Vimming!
Discussion
Loading comments...