Blog
3 min read

Nano Editor Basics: Edit Files in the Terminal Without Panic

Nano is the simplest terminal text editor and is installed on almost every Linux server. How to open a file, save with Ctrl+O, exit with Ctrl+X, search, cut and paste lines, jump to a line number, and edit files that need sudo.

Nano is a small text editor that runs in the terminal. It's on almost every Linux server and Mac, and unlike Vim, it works the way you'd expect: you open a file and start typing.

You'll use it to edit config files over SSH, write a quick .env file, or fix one line on a server.

Open a file

nano notes.txt

If the file doesn't exist, nano creates it when you save. For system files that need admin rights:

sudo nano /etc/nginx/sites-available/myapp

The two shortcuts you need

The bottom of the screen lists shortcuts. ^ means Ctrl, and M- means Alt.

  • Ctrl+O — save ("Write Out"). Press Enter to confirm the file name.
  • Ctrl+X — exit. If there are unsaved changes, it asks: press Y to save, N to discard, then Enter.

Most of the time, Ctrl+X, Y, Enter is all you need.

Other useful shortcuts

Shortcut Action
Ctrl+W Search ("Where is") — then Alt+W for the next match
Ctrl+\ Search and replace
Ctrl+K Cut the current line
Ctrl+U Paste the cut line(s)
Ctrl+_ or Alt+G Go to a line number
Alt+U Undo
Alt+E Redo
Ctrl+C Show the current line number
Alt+N Toggle line numbers (newer versions)

To move a block of lines: press Ctrl+K repeatedly to cut each line, move the cursor, then Ctrl+U to paste them all.

Pasting from your computer

Copying text from your browser and pasting into nano over SSH uses your terminal's paste: usually Ctrl+Shift+V on Linux, Cmd+V on Mac, or right-click in Windows Terminal. Nano's own Ctrl+U only pastes what you cut inside nano.

Jumping to an error line

When an error says nginx: [emerg] ... in /etc/nginx/nginx.conf:42, open the file at that line directly:

sudo nano +42 /etc/nginx/nginx.conf

Common gotchas

  • "Permission denied" when saving — you opened a protected file without sudo. Exit without saving, then reopen with sudo nano. (Linux File Permissions)
  • Long lines wrap or scroll sideways — that's display only; nano doesn't add line breaks unless "hard wrap" is on. Start with nano -w to make sure it won't wrap long lines in config files.
  • YAML and Python care about spaces — nano inserts real tab characters when you press Tab by default. Use spaces, or start nano with nano -E to convert tabs to spaces. (What Is YAML?)

Make nano your git editor

git config --global core.editor "nano"

Now commit messages open in nano instead of Vim.

The summary

  • nano filename to open, Ctrl+O to save, Ctrl+X to exit.
  • Ctrl+W searches, Ctrl+K/Ctrl+U cut and paste lines.
  • Use sudo nano for system files.

EasySpawn lets you ask Claude Code to make server config changes in plain English, with a diff to review, so you only open nano when you want to. See how it works or join the waitlist.

Related: Basic Linux Commands · SSH Into a Server · Environment Variables Explained · Terminal for Beginners

Keep reading