009 — Nano Editor Cheatsheet
009 — Nano Editor Cheatsheet
📝 Nano is a simple terminal text editor. You'll use it on the VPS to create and edit configuration files (
.env,Caddyfile,docker-compose.yml).It's pre-installed on Ubuntu — no setup needed.
Opening Files
# Open existing file
nano filename.txt
# Open file at specific line number
nano +15 filename.txt
# Create new file (just open a name that doesn't exist)
nano newfile.txt
# Open with line numbers shown
nano -l filename.txt
Essential Shortcuts (All You Need)
| Shortcut | Action |
|---|---|
Ctrl+X | Exit (will ask to save) |
Ctrl+O | Save (write out) |
Ctrl+K | Cut entire line |
Ctrl+U | Paste (uncut) line |
Ctrl+W | Search for text |
Ctrl+G | Help (show all shortcuts) |
The Save & Exit Flow (Most Common)
1. Make your edits
2. Press Ctrl+X (exit)
3. It asks: "Save modified buffer?"
4. Press Y (yes)
5. It asks: "File Name to Write:"
6. Press Enter (keep same name)
7. Done! You're back at the terminal.
💡 Memory trick: Just remember
Ctrl+X→Y→Enter. That's 90% of what you need.
Navigation
| Shortcut | Action |
|---|---|
↑ ↓ ← → | Move cursor (arrow keys) |
Ctrl+A | Jump to beginning of line |
Ctrl+E | Jump to end of line |
Ctrl+Y | Page up |
Ctrl+V | Page down |
Ctrl+_ | Go to specific line number |
Ctrl+W | Search, then Ctrl+W again to find next |
Editing
| Shortcut | Action |
|---|---|
Ctrl+K | Cut (delete) current line |
Ctrl+U | Paste the cut line |
Ctrl+K (multiple times) | Cut multiple lines (they stack) |
Alt+6 | Copy current line (without cutting) |
Ctrl+\ | Find and replace |
Ctrl+T | Check spelling (if available) |
Select Text (Mark)
1. Move cursor to start of selection
2. Press Alt+A (or Ctrl+6) to set mark
3. Move cursor to end of selection (text highlights)
4. Press Ctrl+K to cut selection
OR Alt+6 to copy selection
5. Move to destination
6. Press Ctrl+U to paste
Find and Replace
1. Press Ctrl+\
2. Type the text to find → Press Enter
3. Type the replacement text → Press Enter
4. For each match:
- Y = replace this one
- N = skip this one
- A = replace ALL remaining
Example: Replace proxeon with devopsmalaysia:
Ctrl+\ → proxeon → Enter → devopsmalaysia → Enter → A
Bootcamp-Specific Examples
Create .env File
nano ~/kanban-prod/.env
Then paste your content (right-click in terminal to paste), and save:
Ctrl+X→Y→Enter
Edit Caddyfile
nano ~/kanban-prod/Caddyfile
Quick Edit a Single Line
If you just need to change one value (like DATABASE_URL):
nano ~/kanban-prod/.envCtrl+W→ typeDATABASE→Enter(jumps to the line)- Edit the value
Ctrl+X→Y→Enter
View File Without Editing (Use cat Instead)
# Just view contents (no editing)
cat ~/kanban-prod/.env
# View with line numbers
cat -n ~/kanban-prod/Caddyfile
# View long file with scrolling
less ~/kanban-prod/docker-compose.yml
# (press q to quit less)
Common Mistakes & Fixes
"I accidentally opened nano and can't exit"
Press Ctrl+X
If it asks to save → Press N (no, don't save)
You're free!
"I messed up the file and want to discard changes"
Press Ctrl+X
When it asks "Save modified buffer?" → Press N
File reverts to last saved version.
"Pasted text looks weird / has wrong formatting"
This happens when pasting multi-line content. The fix:
# Before pasting, enable "paste mode" in some terminals
# Or just paste — nano handles it reasonably well
# If indentation is broken, you'll need to manually fix lines
# Or delete the file and recreate:
rm ~/kanban-prod/.env
nano ~/kanban-prod/.env
# Paste again carefully
"I need to undo"
Alt+U = Undo
Alt+E = Redo
⚠️ Undo only works for recent edits in the current session. Once you save and close, there's no undo.
Quick Reference Card
╔══════════════════════════════════════════════╗
║ NANO CHEATSHEET ║
╠══════════════════════════════════════════════╣
║ ║
║ SAVE & EXIT: ║
║ Ctrl+X → Y → Enter (save and quit) ║
║ Ctrl+X → N (quit no save) ║
║ Ctrl+O → Enter (save, keep open) ║
║ ║
║ NAVIGATE: ║
║ Ctrl+A / Ctrl+E (start/end of line) ║
║ Ctrl+Y / Ctrl+V (page up/down) ║
║ Ctrl+_ (go to line number) ║
║ ║
║ EDIT: ║
║ Ctrl+K (cut line) ║
║ Ctrl+U (paste line) ║
║ Alt+U (undo) ║
║ Alt+E (redo) ║
║ ║
║ SEARCH: ║
║ Ctrl+W (find) ║
║ Ctrl+\ (find & replace) ║
║ ║
║ HELP: ║
║ Ctrl+G (show all shortcuts) ║
║ ║
╚══════════════════════════════════════════════╝
Alternatives (If You Hate Nano)
| Editor | Open File | Save | Exit | Notes |
|---|---|---|---|---|
nano | nano file | Ctrl+O | Ctrl+X | Simplest, recommended for bootcamp |
vim | vim file | :w | :q (or :wq) | Powerful but steep learning curve |
cat > | cat > file << 'EOF' | Type EOF | Automatic | Good for creating files from scratch |
Create File Without Nano (Paste Entire Content)
If nano gives you trouble, you can create files by pasting directly:
cat > ~/kanban-prod/.env << 'EOF'
DATABASE_URL=Host=...;Port=25060;Database=defaultdb;Username=doadmin;Password=...;SSL Mode=Require;Trust Server Certificate=true
ADMIN_EMAIL=admin@kanban.local
ADMIN_PASSWORD=Admin123!
ADMIN_DISPLAY_NAME=System Admin
ASPNETCORE_ENVIRONMENT=Production
CORS_ORIGINS=https://USERNAME.lazuar.dev
COOKIE_DOMAIN=USERNAME.lazuar.dev
REPO_USER=your-github-username
REPO_PASS=ghp_your_token_here
EOF
This creates the file instantly without opening an editor.