MainspringGuides › nano editor
macOS Guide

Edit Files in Terminal With nano on Mac

Updated July 2026 · 3 min read

Sooner or later a guide tells you to edit a config file in Terminal, and you need an editor that won't trap you. That editor is nano: your arrow keys work, the important shortcuts are printed at the bottom of the screen, and quitting is one keystroke — not a puzzle. Here is everything you need to edit, save, and get out.

Open, edit, save, exit

  1. Run nano filename — for example nano ~/.zshrc. If the file doesn't exist, nano opens a new buffer and creates it when you save.
  2. Type normally. Arrow keys move the cursor; there are no modes to switch, unlike vim.
  3. Press Ctrl+O (WriteOut) to save, then Return to confirm the filename.
  4. Press Ctrl+X to exit. If you have unsaved changes, nano asks Save modified buffer? — press Y then Return, or N to discard.

That last prompt is also your undo for a botched editing session: exit with N and the file on disk is untouched.

The ^ symbol in the shortcut bar means the Control key, not Command — ^O is Ctrl+O. One footnote for the curious: since macOS 12.3, the nano command has actually launched pico, a nearly identical editor Apple ships for licensing reasons — so the nano on Ventura, Sonoma, and Sequoia is pico under the hood. Every shortcut in this guide works the same; if you want full GNU nano, brew install nano gets you the real thing.

Search and move around

Editing protected files with sudo

System files like /etc/hosts are writable only by an administrator. Prefix the command with sudo and enter your password:

# back up first — this is your undo
sudo cp /etc/hosts /etc/hosts.bak

# edit the protected file
sudo nano /etc/hosts

# if something breaks, restore the backup
sudo cp /etc/hosts.bak /etc/hosts

Two cautions. First, make the backup copy every time — a one-character typo in a system file can be genuinely hard to diagnose later. Second, if you opened a system file without sudo, nano will let you edit but fail at the save with "Permission denied"; exit with Ctrl+X, then N, and rerun the command with sudo.

Small flags that help

One habit worth forming: make nano your system-wide default editor, so tools like git and crontab open it instead of vim. Add this line to ~/.zshrc:

# make nano the default for git, crontab, and friends
export EDITOR=nano

# undo: delete the line and open a new window

Reload with source ~/.zshrc, and every tool that respects the EDITOR variable — most do — will drop you into the editor you can actually exit.

Some settings don't need an editor

Config files are for the shell. For everything else, Mainspring turns 90+ hidden macOS settings into labelled toggles — each one reversible with a click, no backup copies required.

Try Mainspring free →

Signed & notarized by Apple · 1-day free trial · $29 once

Where you'll use it next

The file most Mac users end up editing first is their shell config — aliases, PATH, prompt. Our .zshrc guide gives you a worthwhile file to practice on.