█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/DevOps and Infrastructure/Linux and the Command Line/vim Basics
25 minBeginner

vim Basics

After this lesson, you will be able to: Use vim well enough to edit config files on any server: open, insert, edit, save, quit, with zero panic.

vim is everywhere. nano is sometimes missing. Knowing the 10 vim commands that matter means you can edit any file on any server.

Prerequisites:Text Processing

Two modes: Normal and Insert

vim has two modes (really four, but two for this lesson). Normal mode: keys are COMMANDS (move, delete, search, save). Open in this mode. Insert mode: keys are TEXT (type to enter text). Press `i` to enter; `Esc` to leave back to Normal. Most beginner confusion is forgetting which mode they're in. Esc to be safe.

The 10 commands that get you through any edit

Memorise these. You can survive on a server with just these.

bash
# Open
vim file.txt # opens in Normal mode
# Move (Normal mode)
h j k l # left, down, up, right (or just use arrow keys)
w # next word
b # previous word
0 # start of line
$ # end of line
G # end of file
gg # start of file
/foo # search for 'foo' (then n = next, N = previous)
# Edit
i # enter Insert mode (before cursor)
a # enter Insert mode (after cursor)
o # new line below + Insert mode
Esc # back to Normal mode
x # delete character under cursor
dd # delete current line
yy # yank (copy) current line
p # paste below current line
u # undo
Ctrl-r # redo
# Save and quit
:w # save
:q # quit
:wq # save AND quit
:q! # quit WITHOUT saving (force)
:x # alias for :wq

The two scenarios that hurt people

Scenario 1: 'I opened vim by accident, how do I get out?' → `Esc :q! Enter`. Scenario 2: 'I made a tiny edit and want to save.' → `Esc :wq Enter`. Both scenarios are 5 keystrokes. Drill them until they're muscle memory.

When to learn more vim

If you find yourself opening vim every day (sysadmin / SRE), invest a weekend in vimtutor (`vimtutor` command). If you write code daily, you might switch to VS Code with the Vim extension, best of both worlds. Otherwise, the 10 commands above cover 95% of server work.

💡 Default editor for command-line tools

Many CLI tools open an editor: git commit messages, sudo crontab, sudo visudo. If you're more comfortable with nano, set the default: `export EDITOR=nano` in your .bashrc. But know vim well enough to survive when nano isn't installed.

Quick Check

You're on a server, opened a config file in vim, and got stuck. What gets you out without saving?

Pick the exact sequence.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Text Processing: awk, sed, cut
Back to Linux and the Command Line
Passion Project: Hardened VPS Deploy→