Linux

Vim for Beginners: Master the Editor in 20 Minutes

This guide will help you overcome the initial barrier and use Vim effectively—a powerful text editor available on any Linux system. You'll learn basic commands for navigation, editing, saving, and exiting.

15-20 minutes
Easy
Применимо к:Ubuntu 22.04+Debian 11+CentOS 8+Any Linux distribution with Vim installed

Introduction / Why This Matters

Vim is a powerful, console-based text editor that comes preinstalled on virtually every Linux system. Learning it is a critically important skill for system administrators, developers, and anyone who works with servers via SSH. Even if you prefer graphical editors, knowing Vim saves the day when a graphical interface is unavailable. This guide will give you a solid foundation: you'll stop fearing Vim and will be able to comfortably edit configs, scripts, and text files right in the terminal.

Requirements / Preparation

  1. System: Any Linux distribution (Ubuntu, Debian, CentOS, Fedora, etc.).
  2. Access: Permissions to run the terminal and edit target files (sudo may be required for system configs).
  3. Package: Vim is usually already installed. If not, install it:
    • Debian/Ubuntu: sudo apt update && sudo apt install vim
    • RHEL/CentOS/Fedora: sudo yum install vim or sudo dnf install vim

Step-by-Step Guide

Step 1: Launching Vim and Understanding the Interface

Open your terminal (Ctrl+Alt+T in most distributions). To edit a specific file, run:

vim /path/to/file.conf

To create a new file:

vim new_file.txt

After launching, you will see:

  • The title line (at the top) — file information.
  • The main area — the file's content (or empty space).
  • The status line (at the bottom) — where messages and commands appear.

Key point: Right after launch, you are in Normal mode. In this mode, every key is a command for navigation, deletion, copying, etc. You cannot just start typing text. You need to switch modes first.

Step 2: Basic Cursor Movement (Normal Mode)

Practice these commands while in Normal mode. Do not press other keys until you've mastered these.

CommandAction
hLeft
jDown
kUp
lRight

These four keys are the absolute basics. Remember them: h — left, j — down (like the down arrow), k — up, l — right.

Fast movements:

  • w — to the beginning of the next word.
  • b — to the beginning of the previous word.
  • 0 (zero) — to the very start of the line.
  • $ — to the very end of the line.
  • gg — to the very start of the file.
  • G (Shift+g) — to the very end of the file.

💡 Tip: If you press a key and something goes wrong — just press Esc to cancel any incomplete command and return to a clean Normal mode.

Step 3: Insert and Edit Modes

To start typing or editing text, you need to switch to Insert mode.

CommandWhen to UseCursor Will Move To
iInsertBefore the current character
aAppendAfter the current character
oOpenIn a new line below the current one
O (Shift+o)In a new line above the current one

Example:

  1. While in Normal mode, place the cursor on the letter e in the word text.
  2. Press i. The status line at the bottom will show -- INSERT --.
  3. Start typing. Text will be inserted before the e character.
  4. Press Esc. You'll return to Normal mode, and you can control the editor again.

Step 4: Deletion, Replacement, and Undo

All these actions are performed in Normal mode.

  • Deletion:
    • x — delete the character under the cursor (like Delete).
    • dd — delete the entire line the cursor is on.
    • dw — delete the word starting from the cursor.
    • d$ — delete from the cursor to the end of the line.
    • d0 — delete from the cursor to the start of the line.
  • Replacement:
    • r + character — replace the single character under the cursor with the specified one (e.g., rx replaces it with x). You will remain in Normal mode afterward.
  • Undo and Redo:
    • u — undo the last change.
    • Ctrl + r — redo (reverse an undo).

Step 5: Saving and Exiting

Always check which mode you are in! To save and exit, you must be in Normal mode (Esc).

  1. Press : (colon). The cursor will move down to the command line.
  2. Enter one of the commands:
    • :wwrite (save).
    • :qquit (exit). Works only if the file hasn't been changed!
    • :wq — save and exit.
    • ZZ (Shift+zz) — quick alternative to :wq (doesn't require pressing :).
    • :q! — exit without saving, discarding all changes since the last save.
    • :w filename — save with a different name.

Verification

  1. Create a test file: vim test_vim.txt.
  2. Press i, type a few lines of text.
  3. Press Esc.
  4. Try moving around the file with j, k, w, b.
  5. Delete a couple of words (dw) or a line (dd).
  6. Press u — the changes should be undone.
  7. Press : and enter :wq. The file test_vim.txt should be saved in the current directory. Check it: cat test_vim.txt.

If everything succeeded — you've mastered the vital minimum.

Common Issues

  • Issue: When trying to exit (:q), Vim says E37: No write since last change (add ! to override).
    • Cause: The file was changed but not saved.
    • Solution: Either save (:wq) or exit without saving (:q!).
  • Issue: I accidentally pressed a key, and a strange line appeared at the bottom or the text started behaving unpredictably.
    • Solution: Press Esc a few times. This guarantees a return to clean Normal mode.
  • Issue: I can't type text, only move around.
    • Cause: You are in Normal mode.
    • Solution: Press i, a, or o to switch to Insert mode. The status line will show -- INSERT --.
  • Issue: I don't know which mode I'm in.
    • Solution: Just press Esc. If you were in Insert mode, you'll return to Normal. If you were already in Normal — nothing will change. This is a safe "reset".

Next Steps

Having mastered these basics, you can already work. To become faster, learn commands gradually:

  1. Copy and paste: yy (yank/copy line), p (paste after cursor), P (paste before).
  2. Search: /text + Enter (search forward), n — next match, N — previous.
  3. Multiple files: :e filename (open), :bn / :bp (next/previous buffer).
  4. Window splitting: :split (horizontal), :vsplit (vertical).

A useful cheat sheet is always at hand: inside Vim, type :help or search online for "vim cheat sheet". Most importantly — practice. Open any configuration file (/etc/fstab, ~/.bashrc) and try to make changes with Vim. You've got this!

F.A.Q.

How do I exit Vim if I'm stuck?
What's the difference between vi and vim?
Do I need to memorize all Vim commands right away?
Why does Vim seem difficult, and is it worth learning?

Hints

Starting Vim and Understanding the Interface
Basic Cursor Movement (Normal Mode)
Insert and Editing Modes
Deletion, Replacement, and Undo
Saving and Exiting
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community