GNU nano is a lightweight, terminal-based text editor built into almost every Linux distribution and macOS system. Unlike modal editors like Vim, nano is modeless—you type directly into the file and use Ctrl or Alt key combinations for commands.

1. Opening and Creating Files

Launch nano from your terminal by passing a filename. If the file doesn’t exist, nano creates a new buffer in memory and writes it to disk when you save.

  • Open or create a file:

    nano filename.txt
    
  • Open a file at a specific line and column: (Useful for jumping to syntax errors in config files)

    nano +42,10 /etc/nginx/nginx.conf
    
  • Open with line numbers displayed:

    nano -l script.sh
    
  • Open in read-only mode: (Prevents accidental edits to critical system files)

    nano -v /etc/fstab
    

Reading the Bottom Bar: The two rows at the bottom of the screen display your primary shortcuts. The caret symbol (^) represents the Ctrl key, and M- represents the Meta key (Alt on Linux/Windows, or Esc / Option on macOS).

2. Essential Keyboard Shortcuts

ActionShortcutNotes
Save (Write Out)Ctrl + OPrompts for filename; press Enter to confirm.
ExitCtrl + XPrompts to save (Y or N) if there are unsaved changes.
Cut LineCtrl + KCuts the entire current line (or highlighted selection).
Paste (Uncut)Ctrl + UPastes cut/copied text at the cursor.
Copy LineAlt + 6Copies the current line or highlighted selection.
Undo / RedoAlt + U / Alt + EReverts or reapplies recent edits.
SearchCtrl + WType search term and press Enter.
Find NextAlt + WJumps to the next occurrence of your last search.
Search & ReplaceCtrl + \Prompts for search term, replacement, and confirmation (Y, N, or A for All).
Help MenuCtrl + GOpens the full built-in shortcut reference (Ctrl + X to close).

3. Navigation and Text Selection

Moving around large config files is much faster with jump shortcuts than holding down the arrow keys.

  • Beginning / End of line: Ctrl + A / Ctrl + E (or Home / End)
  • Page Up / Page Down: Ctrl + Y / Ctrl + V
  • Top / Bottom of file: Alt + \ / Alt + /
  • Jump to a specific line: Ctrl + _ (or Ctrl + Shift + -), then type the line number and press Enter.

Selecting Blocks of Text

  1. Move the cursor to the start of the text you want to select and press Alt + A (or Ctrl + 6) to set a mark.
  2. Move the cursor with the arrow keys to highlight the block.
  3. Press Ctrl + K to cut or Alt + 6 to copy, then move to the destination and press Ctrl + U to paste.

4. Customizing Your Workflow (~/.nanorc)

You can configure nano’s default behavior permanently by creating or editing a .nanorc file in your home directory (nano ~/.nanorc).

# Show line numbers in the left margin
set linenumbers

# Enable mouse support (click to move cursor, scroll wheel)
set mouse

# Convert tabs to spaces and set tab width to 4
set tabsize 4
set tabstospaces

# Automatically indent new lines to match the previous line
set autoindent

# Enable syntax highlighting for common languages and configs
include "/usr/share/nano/*.nanorc"

5. Common Troubleshooting

  • Permission Denied on Save: If you opened a system file without sudo and get a permission error when pressing Ctrl + O, you don’t need to lose your work. Save it to /tmp/temp.conf, exit nano, and move it over with sudo mv /tmp/temp.conf /path/to/original.

  • Weird Pasting Indentation: Pasting multi-line code from your clipboard can sometimes cause cascading indentation (“stair-stepping”). Press Alt + I to temporarily toggle autoindent off before pasting, then press Alt + I again afterward.

  • Accidental Suspend (Ctrl + Z): If you press Ctrl + Z and drop back to your shell, nano is still running in the background. Type fg and press Enter to bring it right back.