Step 22. Editors — Surviving the Terminal with nano and vim
Level 0 — Understanding Computer Operation and Structure | Difficulty ★★☆☆☆ | Estimated time: 3 hours
Prerequisites: you must be able to use the basic Linux commands from Steps 18–21 (ls, cd, cat, grep, apt). An Ubuntu virtual machine (or WSL) must be running.
- What you need: one Ubuntu terminal. No internet connection needed.
- Caution: today’s exercise is 100% safe. It’s all about creating and editing practice files in your home folder.
- Note: editors are interactive programs that take over the whole terminal, so their screens can’t be transcribed as text. Scenes inside editors are conveyed as "screen descriptions (output examples)," while commands verifiable outside the editor were actually run.
Until now, we’ve only ever "viewed" files with commands. Read them with cat, found things with grep, searched with find. But in real fieldwork, far more moments require you to edit files. Changing a value in a config file, writing a script, leaving a note in a log — all of it is editing. Today you learn terminal editors: tools for editing files inside the terminal.
To be honest, vim — one of today’s two protagonists — is a wall for everyone who meets it for the first time. "I opened vim, couldn’t get out, and closed the terminal" is a shared experience and running joke among developers worldwide. Today we’ll deliberately run into that wall once and etch the escape route into our muscle memory.
1. Learning Objectives
By the end of this chapter, you will be able to:
- Explain why terminal editors are needed, and why
cator>isn’t enough - Create a file with nano and edit, save, and exit it (
Ctrl+O→ Enter →Ctrl+X) - Explain vim’s concept of modes, and perform the survival cycle
i → write → Esc → :wq - Escape vim on your own with
Esc→:q!→ Enter when trapped - Confirm by experiment the difference between "save-and-quit (
:wq)" and "discard-and-quit (:q!)"
2. Background Knowledge — Today’s Tools and Concepts
Today’s Tools at a Glance
| Category | Details |
|---|---|
| Language/Environment | Ubuntu terminal (bash shell), no internet needed |
| Today’s commands | nano filename, vim filename, nano shortcuts (Ctrl+O/Ctrl+X), vim keys (i, Esc, :wq, :q!, dd, yy, p, u, gg, G) |
| Concepts needed | terminal editors, modes (normal/insert/command-line), the basic editing cycle |
2-1. Why a Separate Editor Is Needed
cat only "prints" a file — it can’t "modify" one. You can overwrite a file’s entire content with the > redirection, but fixing just one line of existing content is impossible. An editor is a tool that spreads a file out on screen and lets you move a cursor around to fix it character by character.
On Windows, you’d just open Notepad. But the environments where security professionals work — say, remotely connected to a server that suffered a breach — have only a black terminal on screen. No icons to double-click, no Notepad. What you need then is a terminal editor.
Linux terminal editors fall roughly into two camps: nano, which is easy but limited, and vim, which is hard but powerful and everywhere.
2-2. nano — The Editor with On-Screen Help
nano always shows a list of shortcuts at the bottom of the screen. You’ll see notation like ^O — the ^ means the Ctrl key. So ^O means "press Ctrl+O."
There’s no concept of modes, so typing on the keyboard immediately enters text. It comes preinstalled on Ubuntu, and today you’ll use it to learn the basic flow of "edit–save–exit."
2-3. vim — The Editor with Modes
vim uses a distinctive concept called modes. The same keyboard keys do completely different things depending on the situation.
- Normal mode: the state vim starts in when opened. The letter keys work not as "text input" but as "commands." For example,
ddisn’t the two letters ‘d’ — it’s the "delete one line" command. - Insert mode: entered by pressing
iin normal mode. Only now does the keyboard type text.-- INSERT --appears at the bottom of the screen. PressEscto return to normal mode. - Command-line mode: entered by pressing
:in normal mode. A:appears at the very bottom of the screen, and you type commands like save and quit as text, then execute them with Enter.
Why build something this inconvenient? When vim’s predecessor vi was created in the 1970s, keyboards often had no mouse and no arrow keys. To do all your editing without lifting your hands from the home position, the letter keys themselves had to be commands. And once mastered, the speed of handling text without a mouse becomes unimaginably fast.
One more important fact: vim (or the original vi) is installed on virtually every Unix and Linux system. Minimal installations, ancient servers, embedded devices — wherever you go, vi is there. nano might not be, but vi is. That’s why, for survival, you must know the minimal usage of vim.
3. Follow Along
3-1. Confirming Both Editors Exist
Before the real practice, let’s verify both editors’ presence and versions with query commands:
which nano vim
/usr/bin/nano
/usr/bin/vim
(Verified 2026-09-09 on Ubuntu 24.04.)
nano --version | head -1
vim --version | head -1
GNU nano, version 7.2
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Sep 05 2025 19:44:46)
(Verified 2026-09-09. Versions may differ by environment.)
How to read it: which shows "where the actual file of this command lives." Both are under /usr/bin — "programs installed in the shared system area" from Step 21. Different versions may lay out the screen a bit differently, but the core keys you’ll learn today have been identical for half a century.
3-2. First Editing with nano
nano note.txt
(Screen description, output example) The entire terminal changes to the nano screen. The top is an empty editing space; the bottom two lines show shortcut guidance like ^G Get Help ^O Write Out ^X Exit.
How to read it: you are now "inside" the program called nano. It’s normal that the shell prompt (lee@ubuntu:~$) has disappeared. This isn’t a space for typing commands — it’s a space for writing a document. If you give it a filename that doesn’t exist, nano treats it as a new file and opens an empty document.
Let’s write any three lines:
Today I learned nano.
You can write text in the terminal too.
Surprisingly simple.
Saving: press Ctrl+O. (Screen description, output example) File Name to Write: note.txt appears at the bottom — it’s confirming the name to save under. Just press Enter and a Wrote 3 lines message flashes briefly — saved.
Exiting: press Ctrl+X. nano closes and you return to the familiar shell prompt.
Verify:
cat note.txt
Today I learned nano.
You can write text in the terminal too.
Surprisingly simple.
(That completes the basic editing cycle — create, write, save, exit, verify.)
3-3. vim Basics — Open, Write, Save, Quit
vim note.txt
(Screen description, output example) The screen changes to vim and the three lines from earlier appear. The cursor sits on the first character. Don’t press any keys. Right now you are in normal mode. The filename and line count are shown at the very bottom, and if there’s no -- INSERT --, that means normal mode.
Make a prediction: in this state, if you type
helloon the keyboard, will hello be entered on screen? Write your prediction on paper and try it. (Answer:his interpreted as the command "move left,"eas "move to end of word," and so on — no text is entered. Only the cursor moves around.)
Entering insert mode: press i once. -- INSERT -- appears at the bottom left of the screen. Now the keyboard types text. On a fourth line, let’s write Tried vim too.
Returning to normal mode: press Esc. The -- INSERT -- display disappears.
Save and quit: type :wq and press Enter. vim closes and you return to the shell. : enters command-line mode, w is write (save), q is quit — "save and get out."
Why: vim’s minimal survival cycle for editing is i → write → Esc → :wq. Remember just these five moves and you can fix a config file on whatever server you land on.
3-4. Practicing vim’s Normal Mode
Open it again with vim note.txt. This time, don’t enter insert mode — play only in normal mode:
| Key | What it does |
|---|---|
h j k l |
Move cursor left, down, up, right (arrow keys also work) |
dd |
Delete the line the cursor is on |
yy |
Copy (yank) the line the cursor is on |
p |
Paste below/after the cursor |
u |
Undo the last operation |
gg |
Go to the very top of the file |
G |
Go to the very end of the file |
Experiment 1: move the cursor to the second line and press dd. (Screen description, output example) The line "You can write text in the terminal too." disappears. Press u immediately and it comes back to life.
How to read it: vim supports undo, so there’s no need to fear experiments. If it breaks, press u; if you quit without saving, the original is untouched.
Experiment 2: on any line, press yy, then press p twice. The same line is copied twice below. Even copy-paste finishes in three keystrokes without a mouse — a taste of the "speed" vim users talk about.
When you’re done experimenting, quit without saving: Esc → :q! → Enter (details in the next section).
3-5. Getting Trapped on Purpose and Escaping — Today’s Core Drill
The most important drill. Inside vim, press this and that at random. Getting into strange modes, reaching a state where you don’t know what’s what — that’s the goal.
Escape: press Esc two or three times, then type :q! and press Enter.
(Screen description, output example) Whatever state you were in, vim closes and you return to the shell. Your changes are not saved.
How to read it: the ! in q! means "ignore warnings and force it." It’s the command that ignores vim’s warning "you haven’t saved — are you sure you want to quit?" and leaves anyway.
Why: Esc → :q! → Enter is vim’s universal escape hatch. Whatever weird mode you’re in, this combination gets you out. Because of this one line, countless beginners around the world never had to force-close their terminals.
4. Missions & Exercises
Mission — Editing a Server Setup Plan
Perform the following tasks in order:
- With nano, create
server-setup.txtand write these three lines, then save:[Web server setup plan] 1. Install nginx 2. Open firewall port 80 - Open
server-setup.txtwith vim, add3. Apply TLS certificateas a fourth line in insert mode, then save and quit - Open it again with vim and, using only normal mode, copy (
yy) the second line ("1. Install nginx") and paste it at the very bottom (p), then quit without saving (:q!). Then check the file withcatand confirm the pasted line was not saved - Open it with vim once more, go to the end with
G, return to the top withgg, then quit with:q - Print the final file with
catand review it by eye
The answer isn’t written here — verify it in Section 5.
Exercises
Question 1. Explain the biggest personality difference between nano and vim (the presence of modes), and say what that difference means for a beginner in each case.
Question 2. You typed hello right after opening vim and no text was entered. What state are you in, and what key must you press to enter text?
Question 3. Explain the difference between :wq and :q!, and give one situation for each where it should be used.
Question 4. Explain why the saying "nano might not exist, but vi does" matters in security fieldwork — using a remote server situation as an example.
5. Model Answers & Completion Criteria
Mission Model Answer
nano server-setup.txt # write three lines, Ctrl+O → Enter → Ctrl+X
vim server-setup.txt # i → add fourth line → Esc → :wq
vim server-setup.txt # on the second line: yy → G → p → :q! (don't save!)
cat server-setup.txt # the pasted line must be absent
vim server-setup.txt # G → gg → :q
cat server-setup.txt # final review: only four lines should exist
How to verify: task 3 is the core of this mission. Because you quit with :q!, the paste does not remain in the file. The final cat result being the following four lines means you’re done:
[Web server setup plan]
1. Install nginx
2. Open firewall port 80
3. Apply TLS certificate
If you see five lines (including the copied one), you quit with :wq instead of :q! — feel the difference between "save-and-quit" and "discard-and-quit" in your body once more.
Exercise Answers
Answer 1. nano has no modes — typing on the keyboard immediately enters text, and shortcut help is always visible at the bottom of the screen, so beginners rarely get lost. vim separates normal mode and insert mode, so typing letters right after opening is interpreted as commands, not input — a wall for beginners, but blazing fast without a mouse once mastered.
Answer 2. You’re in normal mode — vim opens in normal mode. You must press i to enter insert mode before text gets entered. Make a habit of checking for the -- INSERT -- display at the bottom of the screen.
Answer 3. :wq is "save and quit" (write + quit); :q! is "force-quit without saving" (discard changes). Use :wq when you’ve finished editing and want to keep it in the file; use :q! when an experiment went wrong or you want to preserve the original.
Answer 4. A field site where you’ve remotely connected to a compromised server has no graphical environment, and there’s no guarantee a familiar editor is installed. Since the vi family exists even on minimal installations, ancient servers, and embedded devices, someone who knows vim’s survival cycle can read and fix files on any server. Someone who knows only nano can do nothing on a server without nano.
Completion Checklist
- [ ] I can create, save, and exit a file with nano
- [ ] I can edit a file in vim with the
i/Esc/:wqcycle - [ ] When trapped in vim, I can escape on my own with
Esc→:q!→ Enter - [ ] I can explain what
dd,yy,p,u,gg, andGeach do - [ ] I can explain the difference between
:wqand:q! - [ ] Mission: I completed all 5 server-setup.txt editing tasks
6. Common Pitfalls & Fixes
Wall 1. "I opened vim and nothing gets typed!"
Symptom: you type letters but nothing is written; only the cursor moves or strange things happen.
Cause: you’re typing letters in normal mode. vim opens in normal mode.
Fix: press i to enter insert mode. The habit of checking for -- INSERT -- at the bottom of the screen is the answer.
Wall 2. "I definitely saved, but the file didn’t change."
Symptom: after leaving vim, cat shows none of your edits.
Cause: you quit with :q!, or you opened a read-only file and ignored the warning.
Fix: always look back at whether you quit with :wq. For a read-only file, vim displays [readonly] at the bottom — in that case you must reopen it with administrator privileges, which is Step 24’s sudo.
Wall 3. "Can’t I exit with Ctrl+C?"
Symptom: you habitually press Ctrl+C but vim doesn’t close.
Cause: in vim, Ctrl+C means "cancel the current input," not quit.
Fix: escape happens only through command-line commands — one of :q, :q!, :wq.
Wall 4. "I keep creating new files while saving in nano."
Symptom: when asked for a filename after Ctrl+O, you type a different name and it saves as a new file instead of the original.
Cause: not understanding the meaning of the File Name to Write: prompt, you edit the name.
Fix: at that prompt, just press Enter. The correct name is already written there.
7. Summary
Today’s Concepts
| Concept | One-line description |
|---|---|
| Terminal editor | A program that edits files inside the terminal — the only editing tool on server sites |
| nano | An easy, modeless editor — help always displayed on screen |
| vim | A powerful modal editor — exists on nearly every Linux system |
| Mode | A structure where the same keys do different things by context (normal/insert/command-line) |
| Survival cycle | i → write → Esc → :wq / universal escape hatch Esc → :q! → Enter |
Today’s Commands & Keys
| Command/Key | What it does |
|---|---|
nano filename |
Open with nano (new file if it doesn’t exist) |
Ctrl+O → Enter / Ctrl+X |
nano save / exit |
vim filename |
Open with vim (starts in normal mode) |
i / Esc |
Enter insert mode / return to normal mode |
:wq / :q! |
Save and quit / discard and quit |
dd yy p u gg G |
Normal mode: delete, copy, paste, undo, top, bottom |
More Important Than Commands: The Instinct
Editor skill is not a measure of security skill. Someone who wields vim flashily isn’t necessarily a good analyst, and there are plenty of excellent professionals who use only nano. What matters is one single survival ability: "can you read and fix files on whatever server you connect to?" What you learned today is exactly that.
Remember two more things. First, at incident-response sites, an editor is a lifeline — opening and reading a script an attacker left behind, in vim or nano, is safe analysis, but "running" it is a different story. Second, if you ever want to learn more, type vimtutor in the terminal — a 30-minute interactive vim course is built in. It’s a hobby, not a requirement — but the survival cycle you practiced today is required. Repeat it two or three more times until your fingers remember it first.
Once every box is checked, Step 22 is complete. Click the checkbox in the sidebar to save your progress.