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.
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.
~/vim-dojo. Do not start by editing production files in /etc.3. Why Vim Matters on Linux Servers
Where you will use it
| Task | Typical command |
|---|---|
| Edit SSH config | sudo vim /etc/ssh/sshd_config |
| Edit hosts file | sudo vim /etc/hosts |
| Edit cron jobs | crontab -e |
| Edit sudoers safely | sudo visudo |
| Edit systemd service | sudo systemctl edit app.service |
Vim vs Nano vs VS Code
| Editor | Best for | Simple analogy |
|---|---|---|
| Nano | Simple quick edits | Notebook |
| Vim | Remote servers and fast edits | Swiss army knife |
| VS Code | Large project development | Full 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.
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.
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.
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.
11. Search and Replace Hunter ๐
| Need | Command |
|---|---|
| Search forward | /word |
| Search backward | ?word |
| Next / previous match | n / N |
| Replace first match on line | :s/old/new/ |
| Replace all in file | :%s/old/new/g |
| Replace all with confirmation | :%s/old/new/gc |
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.
V, move with j/k, then press d to delete, y to copy, > to indent, or < to unindent.13. Files, Buffers, Windows, Tabs
| Action | Command |
|---|---|
| Open another file | :e filename |
| List buffers | :ls |
| Next / previous buffer | :bn / :bp |
| Horizontal split | :split file |
| Vertical split | :vsplit file |
| Move between windows | Ctrl-w w |
| Open tab | :tabnew file |
| Next tab | gt |
PORT=9090
LOG_LEVEL=info
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
15. Real Linux Admin Use Cases
Safe edit checklist
- Backup the file first:
cp file file.bak.$(date +%F). - Open with needed permission only.
- Make small changes.
- Validate syntax with the serviceโs checker.
- Reload, do not restart blindly.
Danger zones
| File/task | Safe approach |
|---|---|
/etc/sudoers | Use sudo visudo |
| crontab | Use crontab -e |
| systemd override | Use sudo systemctl edit name.service |
| SSH daemon config | Run sudo sshd -t before reload |
| nginx config | Run 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
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
cd ~/vim-dojo
vim notes.txt
- Press
i. - Type:
Vim is useful for Linux administration. - Press Esc.
- Type
:wqand press Enter.
Verify
cat notes.txt
Vim is useful for Linux administration.
Mission 2 โ Panic Recovery
cd ~/vim-dojo
cp notes.txt panic.txt
vim panic.txt
- Press
iand type a random test line. - Press Esc.
- Quit without saving:
:q!.
Verify
cat panic.txt
The random test line should not be present.
Mission 3 โ Movement Ninja
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
cd ~/vim-dojo
cat > edit.txt <<'EOF'
keep this line
delete this line
change this word
keep this final line
EOF
vim edit.txt
- Move to line 2 and press
dd. - Press
uto undo. - Press
Ctrl-rto redo. - On line 3, try
dwon a word.
Mission 5 โ Copy and Paste Lines
cd ~/vim-dojo
cat > copy-paste.txt <<'EOF'
server01
server02
server03
EOF
vim copy-paste.txt
- Move to
server01. - Copy line:
yy. - Paste below:
p. - Try
3yyto copy 3 lines.
Mission 6 โ Search and Replace Config Values
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
- Search for
8080using/8080. - Use
nfor next match. - Replace all
8080with9090::%s/8080/9090/g. - Replace
devwithprod::%s/dev/prod/g. - 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
cd ~/vim-dojo
cat > hosts.txt <<'EOF'
server01
server02
server03
EOF
vim hosts.txt
- Use
ggto go to top. - Use block visual mode:
Ctrl-v. - Select the first column for all three lines with
jj. - Press
I, typeprod-, press Esc.
Expected result
prod-server01
prod-server02
prod-server03
Mission 8 โ Safer Admin-style Editing
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
- Change
PermitRootLogin yestoPermitRootLogin no. - Save and quit.
- Compare changes.
diff -u sshd_config.sample.bak sshd_config.sample
sudo sshd -t before reloading the service.Mission 9 โ Macros: The Tiny Robot
cd ~/vim-dojo
cat > macro.txt <<'EOF'
alpha
beta
gamma
delta
epsilon
EOF
vim macro.txt
- Go to top:
gg. - Start recording into register a:
qa. - Insert bullet:
0i-, press Esc. - Move down:
j. - Stop recording:
q. - Replay 4 times:
4@a.
Expected result
- alpha
- beta
- gamma
- delta
- epsilon
Mission 10 โ Build a Practical .vimrc
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
cd ~/vim-dojo
cat > one.conf <<'EOF'
name=one
port=8080
EOF
cat > two.conf <<'EOF'
name=two
port=9090
EOF
vim one.conf
- Open second file:
:e two.conf. - List buffers:
:ls. - Return to previous buffer:
:bp. - Open vertical split:
:vsplit two.conf. - Move between windows:
Ctrl-w w.
Mission 12 โ Final Boss: Fix a Broken Service Config ๐ฎ
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
- Change
APP_ENV=devtoAPP_ENV=prod. - Change
SERVICE_PORT=8080toSERVICE_PORT=9090. - Change
LOG_LEVEL=debugtoLOG_LEVEL=info. - Change
RETRY_COUNT=0toRETRY_COUNT=3. - 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 ๐ชค
| Problem | Likely cause | Fix |
|---|---|---|
| โ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.txtcontains the sentence typed in Mission 1.panic.txtdoes not contain the abandoned test line from Mission 2.app.confhasAPP_ENV=prodand port9090.hosts.txthas theprod-prefix on all three server lines.service.confmatches 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
~/vim-dojo. It does not touch /etc, services, SSH, or package state.20. One-page Cheat Sheet ๐จ๏ธ
operator + motion.