Linux

Vim for Beginners: Essential Commands and Hotkeys

This guide will teach you how to use the Vim editor from scratch. You'll learn to navigate files, make changes, save them, and exit. After completing, you'll confidently use Vim for simple tasks.

Updated at February 17, 2026
15-30 min
Easy
FixPedia Team
Применимо к:Vim 8.0+Neovim 0.5+Any Linux distribution

Introduction / Why This Matters

Vim (Vi IMproved) is a powerful text editor that runs directly in the terminal. Knowing it is critically important for administering Linux servers, where a graphical interface is often unavailable. This guide will dispel the myth of Vim's complexity and give you practical skills for daily work: editing configuration files, viewing logs, making quick code edits. You'll stop fearing the black screen and learn to work efficiently without a mouse.

Requirements / Preparation

  1. Installed Vim. It comes pre-installed on most distributions. Check with: vim --version. If it's missing, install it: sudo apt install vim (Debian/Ubuntu) or sudo yum install vim (RHEL/CentOS).
  2. A terminal (konsole, gnome-terminal, xterm, etc.).
  3. Basic command-line knowledge (cd, ls).
  4. Write permissions in the directory where you'll create/edit files.

Step 1: Starting Vim and Understanding the Interface

Open your terminal and create a test file:

vim test.txt

You'll see a screen similar to this:

"test.txt" [New File]
~
~
~
~
~
~
~
~

What this means:

  • The top line ("test.txt" [New File]) is the status.
  • Tilde (~) marks empty lines after the end of the file.
  • Most importantly: you are in Normal mode (sometimes called Command mode). In this mode, every key you press is a Vim command, not a character to input. If you start typing, nothing will appear. This is normal.

Step 2: Switching to Insert Mode

To start editing text, you need to enter Insert mode.

  1. Press the i key (Latin i).
  2. The prompt -- INSERT -- will appear at the bottom of the screen.
  3. Now type text as you would in a regular editor. For example, enter: Hello, world! This is my first file in Vim.

Quick ways to enter Insert mode:

  • i — insert before the cursor (most common).
  • I — insert at the beginning of the current line.
  • a — insert after the cursor.
  • A — insert at the end of the current line.
  • o — create a new line below the current one and enter Insert mode.
  • O — create a new line above the current one.

Step 3: Navigating the File Without a Mouse

When you finish typing, press Esc — you'll return to Normal mode. Now control the cursor:

Basic movements (single keys):

h — left
j — down
k — up
l — right

Fast navigation:

  • w — jump to the beginning of the next word.
  • b — jump to the beginning of the previous word.
  • 0 (zero) — to the start of the line.
  • $ — to the end of the line.
  • gg — to the very beginning of the file.
  • G (Shift+g) — to the very end of the file.
  • :n or nG — go to line number n (e.g., :15 or 15G).
  • /text + Enter — search forward. n — next match, N — previous.
  • ?text + Enter — search backward.

💡 Tip: Practice the hjkl movements for 5 minutes a day. This is the foundation of speed in Vim.

Step 4: Editing: Delete, Undo, Copy, Paste

All actions are performed in Normal mode.

Deletion:

  • x — delete the character under the cursor.
  • dd — delete (cut) the entire current line.
  • dw — delete the word starting from the cursor.
  • d$ or D — delete from the cursor to the end of the line.
  • dgg — delete from the current line to the beginning of the file.

Undo and redo:

  • u — undo the last change.
  • Ctrl + r — redo an undone change.

Copying (yank) and pasting (put):

  • yy — copy (yank) the current line.
  • yw — copy a word.
  • y$ — copy from the cursor to the end of the line.
  • p — paste (put) the copied content after the cursor/line.
  • P (Shift+p) — paste before the cursor/line.

Visual mode for selection: Press v (character-wise visual mode) or V (line-wise visual mode). Move the cursor (hjkl) to select an area. Then:

  • y — copy the selection.
  • d — delete (cut) the selection.
  • > — indent the selection to the right.
  • < — indent to the left.

Step 5: Saving and Exiting

All save/exit commands start with a colon : and are executed in Normal mode.

  1. Ensure you are in Normal mode (press Esc).
  2. Enter:
    • :w + Enter — save (write) the file.
    • :q + Enter — quit, if there are no unsaved changes.
    • :wq or :x or ZZ — save and quit.
    • :q! — quit without saving changes (forcefully).
    • :w filename — save the current buffer under a different name ("Save As").

Step 6: Working with Multiple Files and Buffers

Vim can handle multiple files simultaneously.

  • :e filename — open (edit) another file in the current window. The current buffer is saved automatically if there were changes? No, you must save explicitly with :w or use :enew for a new file.
  • :bn — go to the next buffer (buffer next).
  • :bp — go to the previous buffer.
  • :ls — list all open buffers.
  • :b n — go to buffer number n (from the :ls list).

Verification

  1. Open your test file: vim test.txt.
  2. Enter Insert mode (i), add a new line.
  3. Return to Normal mode (Esc).
  4. Copy the added line (yy), move to the end of the file (G), paste (p).
  5. Save and exit (:wq).
  6. View the file with cat test.txt — you should see two identical lines.

Common Issues

⚠️ "Frozen" in Vim, nothing happens? You are in Normal mode. Press i to insert text or Esc, then :q! to exit.

⚠️ Can't exit, message "No write since last change (add ! to override)"? You have unsaved changes. Use :wq (save and quit) or :q! (quit without saving).

⚠️ Cursor doesn't move with hjkl keys? You might be using a non-standard layout or have remapped keys. Ensure you are in Normal mode (Esc). Some terminal emulators may have conflicts. Try using the arrow keys.

⚠️ Search (/) doesn't find text that's there? Ensure you are searching for the exact spelling (case-sensitive by default). Use \c at the end of the pattern to ignore case: /text\c. Also, check if old search highlighting remains — clear it with :nohlsearch.

⚠️ Accidentally pressed Ctrl + s and the terminal "froze"? This is standard terminal behavior (XON/XOFF flow control). Unlock it: press Ctrl + q. In Vim, you can disable this by adding set t_ts= t_fs= to your ~/.vimrc (but this is for advanced users).

F.A.Q.

How to properly exit Vim if you're stuck?
How does Normal mode differ from Insert mode?
How to copy and paste a line in Vim?
Why does Vim seem difficult and is it worth learning?

Hints

Starting Vim and understanding the interface
Switching to Insert mode
Navigating the file without a mouse
Editing: deletion, undo, redo
Saving and exiting Vim
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