โ†‘ Top
Linux Learning โ€ข Vim Editor

Vim Dojo
Interactive Reference

A beginner-to-intermediate Vim training document designed for classroom delivery: animated mode visuals, panic rescue, guided labs, mini simulator, flashcards, quizzes, and a final boss lab.

๐Ÿฅท Survival-first learning โŒจ๏ธ Muscle-memory drills ๐Ÿงช Labs with verification ๐ŸŽฎ Progress + XP tracker ๐Ÿ–จ๏ธ Printable cheat sheet
vim notes.txt โ€” animated mode tour
NORMALnotes.txt [+]1,1 All
Press i to insert, Esc to return, :wq to save and quit.

1. Welcome to the Vim Dojo ๐Ÿฅท

Vim feels strange at first because it is a modal editor. In most editors, every key types text. In Vim, keys can be commands, movements, text input, selections, or file commands depending on the current mode.

๐Ÿ›Ÿ

Level 1

Escape, save, quit, type text.

๐Ÿงญ

Level 2

Move without arrow-key dependency.

โš”๏ธ

Level 3

Delete, copy, paste, change, undo.

๐Ÿง™

Level 4

Search, replace, macros, config.

Main idea: Do not try to memorize every Vim command. Learn the grammar: operator + motion. Example: d means delete, w means word, so dw deletes a word.

2. Setup & Prerequisites โš™๏ธ

Vim is commonly available on Linux systems, but minimal server images may include only vi or a tiny Vim build. Verify first, then install only if needed.

Check availability

vim --version | head -5
command -v vim
command -v vi

If vim is missing but vi exists, you can still practice survival commands, but some features may differ.

Install Vim when missing

# Ubuntu / Debian
sudo apt update
sudo apt install vim -y

# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install vim-enhanced -y

On older RHEL-family systems, yum install vim-enhanced -y is also valid.

Training safety: Do the labs in ~/vim-dojo. Do not start by editing production files in /etc.

3. Why Vim Matters on Linux Servers

Where you will use it

TaskTypical command
Edit SSH configsudo vim /etc/ssh/sshd_config
Edit hosts filesudo vim /etc/hosts
Edit cron jobscrontab -e
Edit sudoers safelysudo visudo
Edit systemd servicesudo systemctl edit app.service

Vim vs Nano vs VS Code

EditorBest forSimple analogy
NanoSimple quick editsNotebook
VimRemote servers and fast editsSwiss army knife
VS CodeLarge project developmentFull workshop

Vim wins on servers because it is keyboard-driven, fast over SSH, scriptable, and commonly available even on minimal systems.

4. Vim Panic Button ๐Ÿšจ

Beginners do not hate Vim. They hate being trapped inside Vim. Keep this rescue card visible during training.

Quit without saving

Esc then :q! then Enter

Save and quit

Esc then :wq then Enter

Save only

Esc then :w then Enter

Step 1: Press Esc several times.
Step 2: Type one of these:
  :q!   quit without saving
  :wq   save and quit
  :w    save only
Step 3: Press Enter.

5. Vim Modes: The Secret Door System

Vim is not one room. It is a set of rooms. The same key can do different things depending on the room you are standing in.

NORMALmove, delete, copy
INSERTtype actual text
VISUALselect text
COMMANDsave, quit, replace
i / a / o โ†™
โ†˜ v / V
:
Esc

Mode sequence trainer

Click the sequence and watch the explanation.

Pick a sequence above.

6. Mini Vim Simulator

This is not a real Vim engine, but it helps learners visualize the mental model before touching the terminal.

training.conf โ€” simulator
NORMALtraining.conf1,1
Normal mode. Try i, type, Esc, dd, u, /error, :wq.

7. Movement: Stop Crawling, Start Jumping ๐Ÿงญ

Small moves

h left, j down, k up, l right.

Word moves

w next word, b previous word, e end of word.

Line moves

0 beginning, ^ first non-blank, $ end.

File moves

gg top, G bottom, 25G line 25.

Screen moves

Ctrl-f page down, Ctrl-b page up, zz center current line.

Find on line

fx find next x, tx till x, ; repeat.

Training tip: make learners use only h j k l, w, b, 0, $, gg, and G for 10 minutes. It feels silly, then it clicks.

8. Editing Grammar: Operator + Motion

Vim commands combine like Lego. This is the breakthrough concept.

+ =

Delete

dd line, dw word, d$ to line end.

Change

cw change word, cc change whole line, ci" change inside quotes.

Repeat

. repeats the last change. This is Vimโ€™s little productivity cheat code.

9. Command Recipes: Do This, Press That ๐Ÿณ

Delete a line

Esc dd

Copy 3 lines

Esc 3yy

Paste below

Esc p

Undo / redo

u / Ctrl-r

Go to line 50

:50 or 50G

Replace dev โ†’ prod

:%s/dev/prod/g

Replace with confirmation

:%s/dev/prod/gc

Show line numbers

:set number

Clear search highlight

:noh

10. Shortcut Flashcards

Click each card. Use these for quick classroom recall games.

12. Visual Mode: Select First, Act Later

Character visual

v selects characters. Useful for small selections.

Line visual

V selects full lines. Best for config blocks.

Block visual

Ctrl-v selects columns. Useful for adding/removing prefixes.

Common pattern: select with V, move with j/k, then press d to delete, y to copy, > to indent, or < to unindent.

13. Files, Buffers, Windows, Tabs

ActionCommand
Open another file:e filename
List buffers:ls
Next / previous buffer:bn / :bp
Horizontal split:split file
Vertical split:vsplit file
Move between windowsCtrl-w w
Open tab:tabnew file
Next tabgt
APP_ENV=prod
PORT=9090
LOG_LEVEL=info
APP_ENV=dev
PORT=8080
LOG_LEVEL=debug

14. Beginner-friendly ~/.vimrc

The ~/.vimrc file stores personal Vim settings. Keep it small at first.

set number
set relativenumber
set ruler
set showcmd
set ignorecase
set smartcase
set incsearch
set hlsearch
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
Trainer note: Do not begin with plugin managers. First teach plain Vim: modes, movement, editing, search, replace, buffers, and safe admin editing.

15. Real Linux Admin Use Cases

Safe edit checklist

  1. Backup the file first: cp file file.bak.$(date +%F).
  2. Open with needed permission only.
  3. Make small changes.
  4. Validate syntax with the serviceโ€™s checker.
  5. Reload, do not restart blindly.

Danger zones

File/taskSafe approach
/etc/sudoersUse sudo visudo
crontabUse crontab -e
systemd overrideUse sudo systemctl edit name.service
SSH daemon configRun sudo sshd -t before reload
nginx configRun sudo nginx -t before reload

16. Hands-on Labs: Vim Dojo Missions ๐Ÿงช

Each lab includes setup, objective, commands, expected behavior, and verification. Run labs on a Linux VM or local Linux workstation.

Mission 0 โ€” Prepare the Lab Workspace
Level: BeginnerTime: 5 minGoal: safe practice directory
mkdir -p ~/vim-dojo
cd ~/vim-dojo
printf 'Vim Dojo ready\n' > README.txt
ls -la

Expected output

README.txt should be visible in ~/vim-dojo.
Mission 1 โ€” Open, Insert, Save, Quit
Level: BeginnerSkills: i, Esc, :wq
cd ~/vim-dojo
vim notes.txt
  1. Press i.
  2. Type: Vim is useful for Linux administration.
  3. Press Esc.
  4. Type :wq and press Enter.

Verify

cat notes.txt
Vim is useful for Linux administration.
Mission 2 โ€” Panic Recovery
Level: BeginnerSkills: :q!, :wq
cd ~/vim-dojo
cp notes.txt panic.txt
vim panic.txt
  1. Press i and type a random test line.
  2. Press Esc.
  3. Quit without saving: :q!.

Verify

cat panic.txt

The random test line should not be present.

Mission 3 โ€” Movement Ninja
Level: BeginnerSkills: hjkl, w, b, 0, $, gg, G
cd ~/vim-dojo
cat > movement.txt <<'EOF'
line one has several words
line two is for navigation
line three has another target
line four is near the bottom
line five ends here
EOF
vim movement.txt

Practice these without using arrow keys: j, k, w, b, 0, $, gg, G, 3G.

Mission 4 โ€” Delete, Undo, Redo
Level: BeginnerSkills: dd, dw, u, Ctrl-r
cd ~/vim-dojo
cat > edit.txt <<'EOF'
keep this line
delete this line
change this word
keep this final line
EOF
vim edit.txt
  1. Move to line 2 and press dd.
  2. Press u to undo.
  3. Press Ctrl-r to redo.
  4. On line 3, try dw on a word.
Mission 5 โ€” Copy and Paste Lines
Level: BeginnerSkills: yy, p, P, 3yy
cd ~/vim-dojo
cat > copy-paste.txt <<'EOF'
server01
server02
server03
EOF
vim copy-paste.txt
  1. Move to server01.
  2. Copy line: yy.
  3. Paste below: p.
  4. Try 3yy to copy 3 lines.
Mission 6 โ€” Search and Replace Config Values
Level: IntermediateSkills: /, n, :%s
cd ~/vim-dojo
cat > app.conf <<'EOF'
APP_ENV=dev
APP_PORT=8080
BACKEND_URL=http://127.0.0.1:8080/api
LOG_LEVEL=debug
EOF
vim app.conf
  1. Search for 8080 using /8080.
  2. Use n for next match.
  3. Replace all 8080 with 9090: :%s/8080/9090/g.
  4. Replace dev with prod: :%s/dev/prod/g.
  5. Save and quit.

Verify

cat app.conf
APP_ENV=prod
APP_PORT=9090
BACKEND_URL=http://127.0.0.1:9090/api
LOG_LEVEL=debug
Mission 7 โ€” Visual Mode Block Editing
Level: IntermediateSkills: V, Ctrl-v, I, d
cd ~/vim-dojo
cat > hosts.txt <<'EOF'
server01
server02
server03
EOF
vim hosts.txt
  1. Use gg to go to top.
  2. Use block visual mode: Ctrl-v.
  3. Select the first column for all three lines with jj.
  4. Press I, type prod-, press Esc.

Expected result

prod-server01
prod-server02
prod-server03
Mission 8 โ€” Safer Admin-style Editing
Level: IntermediateSkills: backup, edit, diff
cd ~/vim-dojo
cat > sshd_config.sample <<'EOF'
Port 22
PermitRootLogin yes
PasswordAuthentication yes
EOF
cp sshd_config.sample sshd_config.sample.bak
vim sshd_config.sample
  1. Change PermitRootLogin yes to PermitRootLogin no.
  2. Save and quit.
  3. Compare changes.
diff -u sshd_config.sample.bak sshd_config.sample
On real servers, validate SSH config with sudo sshd -t before reloading the service.
Mission 9 โ€” Macros: The Tiny Robot
Level: IntermediateSkills: qa, q, @a
cd ~/vim-dojo
cat > macro.txt <<'EOF'
alpha
beta
gamma
delta
epsilon
EOF
vim macro.txt
  1. Go to top: gg.
  2. Start recording into register a: qa.
  3. Insert bullet: 0i- , press Esc.
  4. Move down: j.
  5. Stop recording: q.
  6. Replay 4 times: 4@a.

Expected result

- alpha
- beta
- gamma
- delta
- epsilon
Mission 10 โ€” Build a Practical .vimrc
Level: IntermediateSkills: settings, backup
mkdir -p ~/.vim/backup ~/.vim/swap ~/.vim/undo
cp ~/.vimrc ~/.vimrc.backup.$(date +%F-%H%M%S) 2>/dev/null || true
vim ~/.vimrc

Paste the configuration from the .vimrc section, save, and reopen Vim.

vim ~/vim-dojo/app.conf

You should see line numbers and improved search behavior.

Mission 11 โ€” Buffers and Splits
Level: IntermediateSkills: :e, :ls, :vsplit, Ctrl-w
cd ~/vim-dojo
cat > one.conf <<'EOF'
name=one
port=8080
EOF
cat > two.conf <<'EOF'
name=two
port=9090
EOF
vim one.conf
  1. Open second file: :e two.conf.
  2. List buffers: :ls.
  3. Return to previous buffer: :bp.
  4. Open vertical split: :vsplit two.conf.
  5. Move between windows: Ctrl-w w.
Mission 12 โ€” Final Boss: Fix a Broken Service Config ๐ŸŽฎ
Level: Boss FightSkills: movement, edit, search, replace, verify
cd ~/vim-dojo
cat > service.conf <<'EOF'
SERVICE_NAME=inventory
APP_ENV=dev
SERVICE_PORT=8080
LOG_LEVEL=debug
RETRY_COUNT=0
EOF
cp service.conf service.conf.bak
vim service.conf

Tasks inside Vim

  1. Change APP_ENV=dev to APP_ENV=prod.
  2. Change SERVICE_PORT=8080 to SERVICE_PORT=9090.
  3. Change LOG_LEVEL=debug to LOG_LEVEL=info.
  4. Change RETRY_COUNT=0 to RETRY_COUNT=3.
  5. Save and quit.

Verify

cat service.conf
diff -u service.conf.bak service.conf

Expected final file

SERVICE_NAME=inventory
APP_ENV=prod
SERVICE_PORT=9090
LOG_LEVEL=info
RETRY_COUNT=3

17. Common Vim Traps ๐Ÿชค

ProblemLikely causeFix
โ€œI cannot type.โ€You are in Normal mode.Press i.
โ€œCommands are appearing inside the file.โ€You are in Insert mode.Press Esc, then type commands.
โ€œI cannot quit.โ€Unsaved changes exist.:q! to discard or :wq to save and quit.
โ€œI deleted something accidentally.โ€dd, d, or x was pressed.Press u to undo.
โ€œReadonly file.โ€Permission issue or read-only file.Quit and reopen with proper permissions. Avoid forcing writes blindly.
โ€œSwap file warning.โ€Another Vim session, crash recovery, or stale swap.Recover if needed, verify no active session, then remove stale swap carefully.
โ€œSearch highlight is annoying.โ€hlsearch is on.Run :noh.
โ€œBackspace behaves strangely.โ€Default compatibility behavior.Add set backspace=indent,eol,start to ~/.vimrc.

18. Quick Assessment

1. Which key returns you to Normal mode?

2. Which command quits without saving?

3. What does dd do?

4. Which command replaces all occurrences with confirmation?

5. What does qa do?

19. Validate Your Vim Learning โœ…

This section helps trainees prove that they can perform the important Vim tasks without guessing. It validates the lab files, not production configuration.

Manual validation checklist

  • notes.txt contains the sentence typed in Mission 1.
  • panic.txt does not contain the abandoned test line from Mission 2.
  • app.conf has APP_ENV=prod and port 9090.
  • hosts.txt has the prod- prefix on all three server lines.
  • service.conf matches the final boss expected file exactly.

Runnable validator

cat > ~/vim-dojo/validate-vim-dojo.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd "$HOME/vim-dojo"

pass(){ printf 'PASS: %s\n' "$1"; }
fail(){ printf 'FAIL: %s\n' "$1"; exit 1; }

[[ -f notes.txt ]] && grep -qx 'Vim is useful for Linux administration.' notes.txt \
  && pass 'Mission 1 notes.txt saved correctly' || fail 'notes.txt missing expected line'

[[ -f app.conf ]] && grep -qx 'APP_ENV=prod' app.conf \
  && grep -qx 'APP_PORT=9090' app.conf \
  && grep -qx 'BACKEND_URL=http://127.0.0.1:9090/api' app.conf \
  && pass 'Mission 6 app.conf replacements correct' || fail 'app.conf replacements incomplete'

[[ -f hosts.txt ]] && grep -qx 'prod-server01' hosts.txt \
  && grep -qx 'prod-server02' hosts.txt \
  && grep -qx 'prod-server03' hosts.txt \
  && pass 'Mission 7 block edit correct' || fail 'hosts.txt block edit incomplete'

cat > /tmp/vim-dojo-expected-service.conf <<'EXPECTED'
SERVICE_NAME=inventory
APP_ENV=prod
SERVICE_PORT=9090
LOG_LEVEL=info
RETRY_COUNT=3
EXPECTED
cmp -s service.conf /tmp/vim-dojo-expected-service.conf \
  && pass 'Mission 12 final boss config correct' || fail 'service.conf does not match expected final boss output'
EOF
chmod +x ~/vim-dojo/validate-vim-dojo.sh
~/vim-dojo/validate-vim-dojo.sh
Trainer note: This validator intentionally checks only files created in ~/vim-dojo. It does not touch /etc, services, SSH, or package state.

20. One-page Cheat Sheet ๐Ÿ–จ๏ธ

EscReturn to Normal mode.
i / a / oInsert before cursor / append / open new line below.
:w / :q / :wq / :q!Save / quit / save quit / quit without saving.
h j k lLeft / down / up / right.
w b eNext word / previous word / end of word.
0 ^ $Line start / first non-blank / line end.
gg / G / 25GTop / bottom / go to line 25.
dd / dw / d$Delete line / word / to end of line.
yy / 3yy / p / PCopy line / copy 3 lines / paste below / paste above.
u / Ctrl-r / .Undo / redo / repeat last change.
/text / n / NSearch / next / previous.
:%s/old/new/gcReplace all with confirmation.
v / V / Ctrl-vVisual char / visual line / visual block.
:set number / :nohShow line numbers / clear search highlight.
:split / :vsplitHorizontal / vertical split.
:ls / :bn / :bpList buffers / next buffer / previous buffer.
Final mantra: When confused, press Esc. When careful, backup first. When powerful, use operator + motion.