Linux Text Editors: nano and vi/vim Essentials
I built reliable terminal editing skills in nano for quick edits and vi/vim for power editing on any server. Knowing vim's modal model guarantees I can edit a config on a minimal host where vi is the only editor present.
Objective & Context
Every Linux server ships vi; many minimal images ship nothing else. This lab builds confidence in both editors so a remote config edit never becomes a blocker, the practical complement to the scripting labs.
Environment & Prerequisites
- A Linux shell with nano and vim available.
- A sample config file to edit.
- Awareness of vim's normal/insert/command modes.
flowchart LR
N[Normal mode] -->|i| I[Insert mode]
I -->|Esc| N
N -->|:| C[Command mode]
C -->|:wq| Save[Save & quit]
Step-by-Step Execution
1. Quick edit with nano
nano /etc/hosts # Ctrl+O save, Ctrl+X exit2. Edit and save in vim
vim /etc/ssh/sshd_config # i to insert, Esc, :wq to save3. Search and replace in vim
:%s/PermitRootLogin yes/PermitRootLogin no/g"sshd_config" 132L written
Validation & Testing
Make a change in each editor and confirm it persisted with cat; perform a global substitution in vim and verify every occurrence changed. Pass criteria: edits save correctly and the vim substitution is complete and accurate.
Advanced: Troubleshooting
- Stuck in vim: press Esc then
:q!to quit without saving. - Read-only file: reopen with sudo or use
:w !sudo tee %. - Mangled paste: use
:set pastebefore pasting blocks into vim.
Key Results
- Edited configs reliably on minimal hosts with vi only.
- Performed global search/replace across a file in one command.
- Recovered from the common "stuck in vim" trap confidently.
- Chose nano vs vim by task to minimize edit time.