Main Menu

Nano Shortcuts & Commands — Complete Cheat Sheet (Linux + macOS)

Whether you're editing a config file over SSH, tweaking a crontab, or writing a quick script, GNU nano is one of the fastest tools to reach for. Unlike vim, nano shows you its commands right on screen — but learning its keyboard shortcuts still takes time unless you have a solid reference. This guide gives you a complete, corrected cheat sheet, copy-paste examples, platform notes for Linux and macOS, and answers to the most common questions nano users Google every day.

Key notation used throughout this guide: ^ = Ctrl (so ^O means Ctrl+O) | M- = Alt/Meta (so M-U means Alt+U) | On macOS, if Alt doesn't respond, press Esc then the key instead.

TL;DR — Nano Cheat Sheet (Top 20 Shortcuts)

Here are the most-used nano commands at a glance, grouped by task. Full details with examples follow in each section below.

Shortcut Action
File Operations  
Ctrl+O Save (Write Out) file
Ctrl+X Exit nano
Alt+B Save a backup of the file
Ctrl+G Open Help screen
Navigation  
Ctrl+F / → Move one character forward
Ctrl+B / ← Move one character backward
Ctrl+Space Move one word forward
Alt+Space Move one word backward
Ctrl+A / Home Jump to beginning of line
Ctrl+E / End Jump to end of line
Ctrl+V / Page Down Move to next page
Ctrl+Y / Page Up Move to previous page
Alt+\ Jump to top of file
Alt+/ Jump to bottom of file
Editing  
Ctrl+K Cut current line (or marked region)
Alt+6 Copy current line (or marked region)
Ctrl+U Paste (uncut)
Alt+A Set mark (start selecting text)
Alt+U Undo last action
Alt+E Redo last undone action
Search & Replace  
Ctrl+W Open search prompt
Alt+W Repeat last search (next result)
Ctrl+\ Search and replace

Free Download

GNU Nano Cheat Sheet PDF

All shortcuts in one printable page — file operations, navigation, editing, search & replace, and nanorc config. Linux & macOS. GNU nano 4.x+.

↓ Download PDF

Free  ·  A4  ·  Print-friendly

What Is Nano? When Should You Use It?

GNU nano is a lightweight, keyboard-driven terminal text editor that ships pre-installed on most Linux distributions and macOS. It was created as a free replacement for the Pico editor and is maintained by the GNU Project.

Nano is the right choice when you need to:

  • Edit a config file directly on a server over SSH.
  • Make a quick change to a script or crontab.
  • Work in an environment where vim or emacs aren't available.
  • Onboard beginners to terminal editing without a steep learning curve.

nano vs vim vs micro

  nano vim micro
Learning curve Low High Low–Medium
Shortcut hints on screen ✅ Yes ❌ No ✅ Yes
Mouse support Optional Optional ✅ Yes
Syntax highlighting ✅ Yes ✅ Yes ✅ Yes
Script/plugin ecosystem Minimal Extensive Moderate
Pre-installed Most distros Many distros Rarely

How to Install Nano

Most Linux distributions include nano by default. Run nano --version to check. If it's missing, install it with your package manager:

Debian / Ubuntu:

sudo apt update && sudo apt install nano

CentOS / RHEL / AlmaLinux:

sudo yum install nano

Fedora:

sudo dnf install nano

macOS (Homebrew):

brew install nano

macOS ships with an older nano via Xcode tools. Installing via Homebrew gives you the latest GNU nano version with full feature support.

Windows (WSL):

sudo apt update && sudo apt install nano

Nano Quick Start — Open, Edit, Save, and Exit

Open or Create a File

# Open an existing file nano filename.txt
# Create and open a new file nano newfile.txt
# Open a file as root (common for config files) sudo nano /etc/hosts

Save a File (Ctrl+O)

  1. Press Ctrl+O (Write Out).
  2. Nano shows the prompt: File Name to Write: filename.txt
  3. Press Enter to confirm, or type a new name to save as a copy.

Exit Nano (Ctrl+X)

  • If no unsaved changes: nano exits immediately.
  • If there are unsaved changes: nano asks Save modified buffer? (Y/N) — press Y then Enter.

Permission Error When Saving?

If you opened a root-owned file without sudo, you'll see Error writing /etc/hosts: Permission denied. Fix it:

# Close the file without saving, then reopen with sudo:
sudo nano /etc/hosts

# Or, save to a temp file and move it:
nano /tmp/hosts_edit sudo mv /tmp/hosts_edit /etc/hosts

Navigation Keys

These shortcuts move the cursor without touching the mouse.

Shortcut Action
Ctrl+F or → Move one character forward
Ctrl+B or ← Move one character backward
Ctrl+P or ↑ Move to the previous line
Ctrl+N or ↓ Move to the next line
Ctrl+Space Jump one word forward
Alt+Space Jump one word backward
Ctrl+A or Home Jump to the beginning of the line
Ctrl+E or End Jump to the end of the line
Ctrl+Y or Page Up Scroll up one page
Ctrl+V or Page Down Scroll down one page
Alt+\ Jump to the top of the file
Alt+/ Jump to the bottom of the file
Alt+G Go to a specific line number

Example — jump to line 42: Press Alt+G, type 42, press Enter.

Selecting, Cutting, Copying, and Pasting

Nano doesn't use the clipboard in the traditional sense — it uses an internal cut buffer. Here's how it works:

Set a Mark (Start Selecting)

Press Alt+A (or Ctrl+^) to place a mark at the cursor position. Move the cursor to highlight a region. The selection is highlighted.

Cut a Line or Region

Shortcut Action
Ctrl+K Cut the current line (or marked region)
Alt+6 Copy the current line (or marked region) without removing it
Ctrl+U Paste (uncut) the last cut/copied content

⚠️ Common confusion: Many guides online swap these two. Ctrl+K cuts, Alt+6 copies. This is verified against GNU nano 4.x and 7.x.

Example — copy a line and paste it below:

  1. Move cursor to the target line.
  2. Press Alt+6 to copy.
  3. Move to where you want to paste.
  4. Press Ctrl+U to paste.

Example — cut lines 3–7:

  1. Move to line 3.
  2. Press Alt+A to set the mark.
  3. Move to line 7.
  4. Press Ctrl+K to cut the selection.
  5. Move to destination and press Ctrl+U.

Searching and Replacing

Basic Search (Ctrl+W)

  1. Press Ctrl+W to open the search prompt.
  2. Type your search term and press Enter.
  3. Nano jumps to the first match.
  4. Press Alt+W to jump to the next match.

Search is case-insensitive by default. To toggle case sensitivity, press Alt+C inside the search prompt.

Search & Replace (Ctrl+)

  1. Press Ctrl+\ to open the search-and-replace prompt.
  2. Enter the search term, press Enter.
  3. Enter the replacement term, press Enter.
  4. Nano asks: Replace this instance? — press Y to replace, N to skip, A to replace all.

Example — replace all instances of "foo" with "bar":

Ctrl+\
Search: foo
Replace with: bar
Press A to replace all

Regex Search

Inside the search prompt, press Alt+R to toggle regular expression mode. Then you can search using patterns like foo.*bar.

Editing & Text Manipulation

Undo and Redo

Shortcut Action
Alt+U Undo the last action
Alt+E Redo the last undone action

Nano supports unlimited undo/redo within a session.

Other Common Editing Commands

Shortcut Action
Ctrl+D or Delete Delete character under cursor
Ctrl+H or Backspace Delete character before cursor
Alt+D Delete from cursor to end of word
Alt+Backspace Delete from cursor to beginning of word
Alt+J Justify (reflow) current paragraph
Alt+M Toggle mouse support on/off
Ctrl+L Refresh/redraw the screen

Working with Multiple Files and Buffers

Nano can open more than one file at a time using buffers.

# Open multiple files
nano file1.txt file2.txt

Shortcut Action
Alt+< Switch to the previous buffer (file)
Alt+> Switch to the next buffer (file)
Ctrl+R Insert (read) another file into the current buffer

Example — insert contents of template.txt into your current file:

  1. Position cursor where you want the content inserted.
  2. Press Ctrl+R.
  3. Type template.txt and press Enter.

Advanced: nanorc & Customisation

The ~/.nanorc file (or /etc/nanorc system-wide) controls nano's default behaviour. Here's a practical example:

# ~/.nanorc
# Enable syntax highlighting (include all bundled definitions) include "/usr/share/nano/*.nanorc"
# Show line numbers set linenumbers
# Enable mouse support set mouse
# Use soft wrapping instead of cutting long lines set softwrap
# Disable automatic line wrapping (useful for code) set nowrap
# Show cursor position in the status bar set constantshow
# Set tab width to 4 spaces set tabsize 4 # Convert tabs to spaces set tabstospaces

Apply changes by saving the file — they take effect next time you open nano.

Custom Key Bindings

You can rebind keys in ~/.nanorc:

# Rebind Ctrl+Z to undo (instead of suspend)
bind ^Z undo main


Common Workflows

Workflow 1 — Edit a Server Config File Over SSH

ssh user@your-server
sudo nano /etc/nginx/nginx.conf
# Make changes
# Ctrl+O → Enter to save
# Ctrl+X to exit
sudo systemctl reload nginx

Workflow 2 — Edit a Crontab

EDITOR=nano crontab -e
# Add your cron job, e.g.:
# 0 2 * * * /home/user/backup.sh
# Ctrl+O → Enter to save, Ctrl+X to exit

Workflow 3 — Quick Script Edit

nano ~/scripts/deploy.sh
# Add or modify lines
# Alt+U to undo if you make a mistake
# Ctrl+O → Enter, Ctrl+X
chmod +x ~/scripts/deploy.sh

Troubleshooting & Common Problems

Alt Keys Not Working (macOS / iTerm2)

On macOS Terminal or iTerm2, the Alt/Option key may not send the Meta signal nano expects.

Fix for iTerm2: Go to Preferences → Profiles → Keys and set Left Option Key to Esc+.

Universal workaround: Press Esc then the key immediately after. For example, instead of Alt+U (undo), press Esc then U.

Permission Denied When Saving

This happens when you open a root-owned file without sudo. Options:

  1. Press Ctrl+X → N (don't save), reopen with sudo nano filename.
  2. Save to a different location and move the file manually.

Nano Freezes After Ctrl+S

Ctrl+S is a terminal flow-control shortcut (XOFF), not a nano command — it freezes input. Press Ctrl+Q to unfreeze. Use Ctrl+O to save in nano.

Which nano Version Am I Running?

nano --version

Some shortcuts (like Alt+G for go-to-line) require nano 4.0+. Syntax highlighting definitions require version 2.x+. The macOS system nano is often very old — install via Homebrew for the latest version.

Full Nano Shortcuts Reference

File Operations

Shortcut Action
Ctrl+O Save the file (Write Out)
Ctrl+X Exit nano
Alt+B Save a backup copy before overwriting
Ctrl+G Open the help screen
Ctrl+R Read/insert another file at cursor

Navigation

Shortcut Action
Ctrl+F / → One character forward
Ctrl+B / ← One character backward
Ctrl+P / ↑ Previous line
Ctrl+N / ↓ Next line
Ctrl+Space One word forward
Alt+Space One word backward
Ctrl+A / Home Beginning of line
Ctrl+E / End End of line
Ctrl+Y / Page Up Previous page
Ctrl+V / Page Down Next page
Alt+\ Top of file
Alt+/ Bottom of file
Alt+G Go to line number

Editing

Shortcut Action
Ctrl+K Cut line or marked region
Alt+6 Copy line or marked region
Ctrl+U Paste (uncut)
Alt+A Set mark (begin selection)
Alt+U Undo
Alt+E Redo
Ctrl+D Delete character under cursor
Alt+D Delete to end of word
Alt+J Justify paragraph
Ctrl+L Refresh screen

Search & Replace

Shortcut Action
Ctrl+W Open search
Alt+W Next search result
Ctrl+\ Search and replace
Alt+R Toggle regex in search
Alt+C Toggle case sensitivity in search

References & Further Reading

Conclusion

GNU nano is the most approachable terminal text editor for everyday server tasks, quick script edits, and config file changes. Mastering its keyboard shortcuts — especially save (Ctrl+O), cut/copy/paste (Ctrl+K / Alt+6 / Ctrl+U), search (Ctrl+W), and undo (Alt+U) — covers the vast majority of real-world use cases.

Bookmark this cheat sheet, drop a .nanorc in your home directory to enable syntax highlighting and line numbers, and you'll be navigating terminal editing faster than ever.

For a deeper dive into working with nano on your VPS or dedicated server, see our related guides: How to Use Nano Text Editor, How to Save and Exit Nano, and How to Search in Nano.

Category: Tutorials Server

Write Comment