Skip to main content
In this lesson you’ll see a live demo of editing text files using Vim. The objective is simple: after following the steps you should be comfortable opening, modifying, and saving files directly from the terminal. We will:
  • prepare a working copy of /etc/passwd,
  • open it with Vim,
  • switch between modes,
  • perform common edits,
  • save and exit.
A dark-themed UI mockup titled "Demo — Editing Text Files" showing stacked buttons with steps like "Open a file," "Switch between modes," "Make changes," and "Save."
Step 1 — Prepare a working copy of /etc/passwd
  • Become root (or use sudo).
  • Copy /etc/passwd to a working file named editme in the student’s home directory, then open it with Vim:
Be careful when editing system files like /etc/passwd. Always work on a copy (as shown above) and never edit your live system files unless you know the exact impact. Mistakes can prevent logins or break services.
Step 2 — Vim modes (quick overview) Vim operates with distinct modes. Knowing which mode you’re in is essential for the right behavior.
Vim commands are case- and context-sensitive. Press Esc to ensure Normal mode before using movement or command keys (for example dd, x, /pattern, :wq). If unsure, press Esc a few times to return to Normal mode.
Step 3 — Example file contents Below is an excerpt of the copied file (/home/student/editme). Use this sample to follow along with editing examples:
Step 4 — Common editing operations Here are the most frequently used commands and workflows for quick edits. Insert, change, and exit insert mode:
  • i — enter Insert mode (insert before cursor).
  • a — enter Insert mode after cursor.
  • o — open a new line below and start Insert mode.
  • Esc — return to Normal mode.
Delete operations:
  • dd — delete the entire current line.
  • x — delete the character under the cursor.
  • In Visual mode, select then press d to delete selection.
Undo / Redo:
  • u — undo last change.
  • Ctrl-r — redo.
Copy (yank) and paste:
  • yy — yank (copy) the current line.
  • In Visual mode, highlight and press y to yank.
  • Move to target and press p to paste after the cursor or P to paste before.
Visual selection modes:
  • v — character-wise selection.
  • V — line-wise selection.
  • Ctrl-v — block (column) selection (useful for column edits).
Common commands reference table Step 5 — Searching Search forward with / from Normal mode:
  • Press n to jump to the next match.
  • Press N to jump to the previous match.
Tip: Combine searches with motions. For example :/^student searches for lines starting with student. Step 6 — Saving and quitting Use colon commands from Normal mode. Examples:
Enter : to start command-line mode, then type the command and press Enter. Step 7 — Learn more with vimtutor For a guided, interactive tutorial run vimtutor:
  • Vim Tutor is included with many Linux distributions, including Red Hat Enterprise Linux.
  • It provides step-by-step lessons covering insertions, movements, text objects, and more.
Wrapping up Practice switching modes (i, Esc, v, V, Ctrl-v) and using Normal-mode commands (dd, x, yy, y, p, /pattern, :wq) to build speed and precision. With repeated use, Vim becomes a very fast and powerful editor for terminal-based workflows. Links and references

Watch Video

Practice Lab