Vim’s modal nature means you’re never just typing; you’re issuing commands that change its state.

Here’s Vim in action, manipulating a configuration file.

# Opening the file
vim /etc/nginx/nginx.conf

# Navigating to line 50
50G

# Inserting text at the end of the current line
A
# Type new configuration here
# Press <Esc> to exit insert mode

# Deleting the next 3 words
3dw

# Searching for "server_name"
/server_name<CR>

# Replacing "localhost" with "example.com" globally
:%s/localhost/example.com/g

# Saving and quitting
:wq

The core problem Vim solves is efficient text manipulation without taking your hands off the home row. It achieves this through distinct modes: Normal, Insert, Visual, and Command-line. Each mode has a specific purpose, preventing accidental edits and allowing for powerful, composable commands. Normal mode is your default state for navigation and execution; Insert mode is for typing text; Visual mode allows selection; and Command-line mode is for complex operations like search and replace.

Let’s break down a typical workflow:

  1. Opening and Navigating: You start in Normal mode. Commands like hjkl move the cursor character by character (left, down, up, right), while w moves forward by word, and b moves backward. gg goes to the top of the file, G to the bottom. For specific lines, 50G jumps to line 50.

  2. Entering Insert Mode: To type, you need to enter Insert mode. i inserts before the cursor, a inserts after, I inserts at the beginning of the line, and A inserts at the end. Once you’re done typing, press <Esc> to return to Normal mode.

  3. Editing and Deleting: In Normal mode, you can delete text with d. dw deletes from the cursor to the start of the next word. d$ deletes to the end of the line. You can combine a count with these: d3w deletes three words. x deletes the character under the cursor.

  4. Search and Replace: Command-line mode, accessed by typing :, is where the real power lies for bulk changes. /pattern<CR> searches forward for "pattern". ?pattern<CR> searches backward. To replace, use :s/old/new/flags. % before the s signifies operating on the entire file. g as a flag means "global" – replace all occurrences on a line. So, :%s/localhost/example.com/g replaces every "localhost" with "example.com" in the entire file.

  5. Saving and Quitting: :w saves, :q quits. :wq does both. :q! quits without saving.

The mental model hinges on understanding that commands are often verbs followed by nouns or motion specifiers. d (delete) is a verb. w (word) is a noun/motion. So dw means "delete a word." c (change) works similarly: cw means "change a word." You can also combine operators with visual selections. Select text in Visual mode (v), then press d to delete it.

Many users struggle with the transition between modes. The key is to always be mindful of which mode you’re in. If you’re unsure, pressing <Esc> multiple times will always bring you back to Normal mode, a safe place to reorient yourself. Furthermore, Vim’s command structure is remarkably consistent. Once you learn d for delete, you’ll find c for change, y for yank (copy), and p for paste behave in analogous ways with the same motion specifiers.

The next hurdle is mastering Vim’s extensive plugin ecosystem.

Want structured learning?

Take the full Vim course →