Nano Cheatsheet
DevOps
nanotext-editorterminalgnusysadmin
Nano Cheatsheet
GNU Nano is a simple, modeless terminal editor. Every keystroke is either text or a command — no modes to remember. Ideal for quick edits and SSH sessions.
Nano
GNU Nano is a simple, modeless terminal editor. Every keystroke is either text or a command — no modes to remember. Ideal for quick edits and SSH sessions.
Basic Keybindings
# Start Nano
nano file.txt # open or create file
nano +10 file.txt # open at line 10
nano -l file.txt # show line numbers
nano -B file.txt # create backup on save (.save)
nano -m file.txt # enable mouse support
| Key | Action | Description |
|---|---|---|
Ctrl+G | Help | Show built-in help (lists all shortcuts) |
Ctrl+O | Save | Write file to disk (prompts for filename) |
Ctrl+X | Exit | Close Nano (prompts to save if modified) |
Ctrl+K | Cut | Cut current line (or selected text) |
Ctrl+U | Paste | Paste last cut text |
Ctrl+T | Spell | Run spell checker (if configured) |
Ctrl+J | Justify | Reformat/justify current paragraph |
Navigation
| Key | Action |
|---|---|
Ctrl+A | Beginning of line |
Ctrl+E | End of line |
Ctrl+Y | Page up |
Ctrl+V | Page down |
Ctrl+F | Move forward one character |
Ctrl+B | Move back one character |
Ctrl+Space | Next word |
Alt+Space | Previous word |
Ctrl+_ | Go to specific line (enter line number) |
Alt+G | Go to specific line (alternative) |
Ctrl+C | Show current cursor position (line, column) |
Alt+] | Go to matching bracket |
Alt+( or Alt+) | Go to previous/next paragraph |
Search & Replace
# Search
Ctrl+W # search forward
Alt+W # search backward
Alt+Q # search without regex
# Replace
Ctrl+\ # search and replace (prompted)
# Enter search text, press Enter
# Enter replacement text
# Y = replace this, N = skip, A = replace all, Ctrl+C = cancel
Cut, Copy & Paste
| Key | Action |
|---|---|
Alt+A | Start/select text marking |
Ctrl+6 | Toggle mark (alternative) |
Ctrl+K | Cut marked text or current line |
Alt+6 | Copy marked text (doesn't cut) |
Ctrl+U | Paste (uncut) last cut/copied text |
File Operations
| Key | Action |
|---|---|
Ctrl+R | Insert file (read a file into current buffer) |
Ctrl+O | Write out (save) — Alt+D to save with different name |
Ctrl+X | Exit |
.nanorc Configuration
# ~/.nanorc — Nano configuration
# Line display
set linenumbers
set constantshow # always show cursor position
# Editing behavior
set tabsize 4
set tabstospaces
set autoindent
set cutoff # hard-wrap at 80 chars (or set fill 80)
set multibuffer # insert-to-end, not replacing buffer
# Backup & history
set backup
set historylog
set mouse
# Syntax highlighting
include /usr/share/nano/*.nanorc
# Or include specific files:
include /usr/share/nano/sh.nanorc
include /usr/share/nano/python.nanorc
include /usr/share/nano/javascript.nanorc
include /usr/share/nano/html.nanorc
include /usr/share/nano/yaml.nanorc
include /usr/share/nano/dockerfile.nanorc
include /usr/share/nano/systemd.nanorc
Custom Syntax Highlighting
# Add to ~/.nanorc
# Custom syntax for .env files
syntax "env" "\.env$"
color brightwhite "^.*="
color cyan "^[A-Z_]+="
color yellow "\"[^\"]*\""
color green "\'[^\']*\'"
# Custom syntax for log files
syntax "logs" "\.log$"
color brightred "ERROR"
color brightyellow "WARN(ING)?"
color brightgreen "INFO"
color brightmagenta "DEBUG"
color blue "^[0-9]{4}-[0-9]{2}-[0-9]{2}"
Common Flags
nano # basic editor
nano -B file.txt # create backup file on save
nano -E file.txt # tab-to-space conversion
nano -l file.txt # show line numbers
nano -m file.txt # enable mouse
nano -S file.txt # smooth scrolling
nano -c file.txt # show cursor position constantly
nano -i file.txt # auto-indent new lines
nano -u file.txt # undo support (default in modern Nano)
nano -r 120 file.txt # set fill column to 120
nano -v file.txt # view mode (readonly)
nano -w file.txt # don't wrap long lines
nano -R file.txt # enable regular expression search
Practical Nano Workflow
# Quick SSH config edit
ssh server
sudo nano /etc/ssh/sshd_config
# Edit, Ctrl+O to save, Ctrl+X to exit
sudo systemctl restart sshd
# Edit a Docker Compose file with syntax highlighting
nano docker-compose.yml
# Create a new script with line numbers
nano -l -i deploy.sh
# View a log file (readonly mode)
nano -vw /var/log/syslog
# Search with Ctrl+W, page with Ctrl+Y/Ctrl+V
Tips
Enable Syntax Highlighting System-Wide
```bash
Install Nano syntax files (Debian/Ubuntu)
sudo apt install nano-syntax-highlighting
Enable all syntax highlighting for all users
echo "include /usr/share/nano/*.nanorc" | sudo tee -a /etc/nanorc ```
Choosing Nano
```bash
Quick SSH config edit on a remote server
nano /etc/nginx/nginx.conf
Edit a Docker Compose file with syntax highlighting
nano docker-compose.yml
View a log file (readonly mode)
nano -vw /var/log/syslog ```
Next Steps
- Bash CLI Tools Cheat Sheet — Unix command-line utilities for power users
- Vim Cheat Sheet — Powerful modal editor for rapid editing
- Emacs Cheat Sheet — Extensible Lisp-based editor