Terminal GuideTerminal Guide
nano icon

nano

Text Editors
macOSLinux
C

Simple and beginner-friendly text editor.

Official Website

Features

Simple InterfaceSyntax HighlightingSearch & Replace

Installation

Homebrew
brew install nano
APT (Debian/Ubuntu)
apt install nano
Pacman (Arch)
pacman -S nano

Why Use Nano?

Nano is the terminal editor with the lowest learning curve. With no concept of modes and shortcuts always visible at the bottom of the screen, even first-time users can navigate without confusion.

Always-On Help

Major keyboard shortcuts are always displayed at the bottom. No need to memorize commands.

Start Editing Immediately

No mode switching needed. Start typing as soon as you open a file.

Intuitive Operations

Save with Ctrl+O, exit with Ctrl+X. Design follows common shortcuts.

Available Everywhere

Pre-installed on most Linux distributions. A lifesaver for those struggling with vi.

Installation

Installation
# macOS (Homebrew)
brew install nano

# Ubuntu/Debian (usually pre-installed)
sudo apt install nano

# Fedora
sudo dnf install nano

# Arch Linux
sudo pacman -S nano

# CentOS/RHEL
sudo yum install nano

# Check version
nano --version

Screen Layout

Nano's screen consists of 3 areas.

GNU nano 7.2 filename.txt Modified
This is the main editing area.
You can input and edit text
just like a normal text editor.
Move with arrow keys,
delete with Backspace/Delete.
^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute
^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify

Header (Top): Filename and edit status

Edit Area (Center): Where you edit text

Shortcut Bar (Bottom): Available commands (^ means Ctrl key)

Basic Operations

Basic Operations
# Open a file
nano filename.txt

# Create a new file
nano newfile.txt

# Open in read-only mode
nano -v filename.txt

# Open and jump to a specific line
nano +10 filename.txt

# Open with line numbers displayed
nano -l filename.txt

# Create backup while editing
nano -B filename.txt

# Start without configuration file
nano -I filename.txt

Frequently Used Commands

^ means Ctrl key, M- means Alt (Meta) key.

File Operations

KeyDescription
Ctrl+OSave file (Write Out)
Ctrl+XExit nano (prompts to save if modified)
Ctrl+RInsert content from another file (Read File)
Ctrl+GDisplay help

Movement

KeyDescription
Arrow keysMove cursor
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+YPrevious page (Page Up)
Ctrl+VNext page (Page Down)
Alt+\Move to beginning of file
Alt+/Move to end of file
Ctrl+_Jump to specific line

Editing

KeyDescription
Ctrl+KCut line
Ctrl+UPaste cut line (Uncut)
Alt+6Copy line
Ctrl+JFormat line (Justify)
Alt+UUndo
Alt+ERedo

Search and Replace

KeyDescription
Ctrl+WSearch (Where Is)
Alt+WSearch next
Ctrl+\Search and Replace

Selection (Mark)

KeyDescription
Alt+AStart mark (begin selection)
Ctrl+6Start mark (alternative key)
After marking, expand selection by moving cursor. Cut with Ctrl+K, copy with Alt+6

Configuration File

Customize settings in ~/.nanorc or /etc/nanorc.

~/.nanorc
# Show line numbers
set linenumbers

# Auto-indent
set autoindent

# Convert tabs to spaces
set tabstospaces

# Set tab width to 2
set tabsize 2

# Enable mouse support
set mouse

# Disable line wrapping
set nowrap

# Smooth scrolling
set smooth

# Create backups
set backup
set backupdir "~/.nano/backups"

# Save undo history
set historylog

# Hide shortcut bar at bottom
# set nohelp

# Always show status bar
set constantshow

# Highlight matching brackets
set matchbrackets "(<[{)>]}"

# Case-sensitive search
set casesensitive

# Enable syntax highlighting
include "/usr/share/nano/*.nanorc"
include "/usr/share/nano/extra/*.nanorc"

# Custom keybindings (examples)
# bind ^S savefile main
# bind ^Q exit main
# bind ^Z undo main
# bind ^Y redo main

Syntax Highlighting

Nano supports syntax highlighting for programming languages and configuration files.

Syntax File Locations

Syntax Files
# Standard syntax files
/usr/share/nano/

# Additional syntax files (varies by distribution)
/usr/share/nano/extra/

# User-defined syntax files
~/.nano/

Enhanced Syntax Highlighting

Installation
# scopatz/nanorc (supports more languages)
curl https://raw.githubusercontent.com/scopatz/nanorc/master/install.sh | sh

# or install manually
git clone https://github.com/scopatz/nanorc.git ~/.nano
echo "include ~/.nano/*.nanorc" >> ~/.nanorc

Common Use Cases

Editing Configuration Files

Configuration File Editing
# Edit system configuration files
sudo nano /etc/hosts
sudo nano /etc/ssh/sshd_config
sudo nano /etc/nginx/nginx.conf

# Edit user configuration files
nano ~/.bashrc
nano ~/.zshrc
nano ~/.gitconfig

Set Nano as Git's Default Editor

Git Configuration
# Set nano as Git's default editor
git config --global core.editor "nano"

# Now nano will be used for editing commit messages
git commit  # nano will start

Editing Crontab

Crontab
# Set EDITOR to nano and edit crontab
EDITOR=nano crontab -e

# or set permanently
echo 'export EDITOR=nano' >> ~/.bashrc

Tips

  • You can always display help with Ctrl+G. See all commands in a list.
  • When saving, press Ctrl+O to confirm the filename. Press Enter to confirm, Ctrl+C to cancel.
  • To cut multiple lines at once, press Ctrl+K repeatedly. All cut lines can be pasted at once.
  • On macOS terminal, press Esc then the key instead of Alt, or enable "Option as Meta key" in terminal settings.
  • Recent nano (4.0+) supports Undo with Alt+U and Redo with Alt+E.
  • Display line numbers by starting with nano -l or toggle with Alt+#.
  • When you need a more feature-rich editor, micro is recommended as a nano alternative.
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More