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)

ShortcutAction
Ctrl+XExit (will ask to save)
Ctrl+OSave (write out)
Ctrl+KCut entire line
Ctrl+UPaste (uncut) line
Ctrl+WSearch for text
Ctrl+GHelp (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.


ShortcutAction
↑ ↓ ← →Move cursor (arrow keys)
Ctrl+AJump to beginning of line
Ctrl+EJump to end of line
Ctrl+YPage up
Ctrl+VPage down
Ctrl+_Go to specific line number
Ctrl+WSearch, then Ctrl+W again to find next

Editing

ShortcutAction
Ctrl+KCut (delete) current line
Ctrl+UPaste the cut line
Ctrl+K (multiple times)Cut multiple lines (they stack)
Alt+6Copy current line (without cutting)
Ctrl+\Find and replace
Ctrl+TCheck 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):

  1. nano ~/kanban-prod/.env
  2. Ctrl+W → type DATABASE → Enter (jumps to the line)
  3. Edit the value
  4. 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)

EditorOpen FileSaveExitNotes
nanonano fileCtrl+OCtrl+XSimplest, recommended for bootcamp
vimvim file:w:q (or :wq)Powerful but steep learning curve
cat >cat > file << 'EOF'Type EOFAutomaticGood 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.

Built with LogoFlowershow