nano
Simple and beginner-friendly text editor.
Official WebsiteFeatures
Installation
brew install nanoapt install nanopacman -S nanoWhy 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
# 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 --versionScreen Layout
Nano's screen consists of 3 areas.
Header (Top): Filename and edit status
Edit Area (Center): Where you edit text
Shortcut Bar (Bottom): Available commands (^ means Ctrl key)
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.txtFrequently Used Commands
^ means Ctrl key, M- means Alt (Meta) key.
File Operations
| Key | Description |
|---|---|
Ctrl+O | Save file (Write Out) |
Ctrl+X | Exit nano (prompts to save if modified) |
Ctrl+R | Insert content from another file (Read File) |
Ctrl+G | Display help |
Movement
| Key | Description |
|---|---|
Arrow keys | Move cursor |
Ctrl+A | Move to beginning of line |
Ctrl+E | Move to end of line |
Ctrl+Y | Previous page (Page Up) |
Ctrl+V | Next page (Page Down) |
Alt+\ | Move to beginning of file |
Alt+/ | Move to end of file |
Ctrl+_ | Jump to specific line |
Editing
| Key | Description |
|---|---|
Ctrl+K | Cut line |
Ctrl+U | Paste cut line (Uncut) |
Alt+6 | Copy line |
Ctrl+J | Format line (Justify) |
Alt+U | Undo |
Alt+E | Redo |
Search and Replace
| Key | Description |
|---|---|
Ctrl+W | Search (Where Is) |
Alt+W | Search next |
Ctrl+\ | Search and Replace |
Selection (Mark)
| Key | Description |
|---|---|
Alt+A | Start mark (begin selection) |
Ctrl+6 | Start 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.
# 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 mainSyntax Highlighting
Nano supports syntax highlighting for programming languages and configuration files.
Syntax File Locations
# Standard syntax files
/usr/share/nano/
# Additional syntax files (varies by distribution)
/usr/share/nano/extra/
# User-defined syntax files
~/.nano/Enhanced Syntax Highlighting
# 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" >> ~/.nanorcCommon Use Cases
Editing Configuration Files
# 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 ~/.gitconfigSet Nano as Git's Default Editor
# 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 startEditing Crontab
# Set EDITOR to nano and edit crontab
EDITOR=nano crontab -e
# or set permanently
echo 'export EDITOR=nano' >> ~/.bashrcTips
- •You can always display help with
Ctrl+G. See all commands in a list. - •When saving, press
Ctrl+Oto confirm the filename. Press Enter to confirm, Ctrl+C to cancel. - •To cut multiple lines at once, press
Ctrl+Krepeatedly. All cut lines can be pasted at once. - •On macOS terminal, press
Escthen the key instead of Alt, or enable "Option as Meta key" in terminal settings. - •Recent nano (4.0+) supports Undo with
Alt+Uand Redo withAlt+E. - •Display line numbers by starting with
nano -lor toggle withAlt+#. - •When you need a more feature-rich editor,
microis recommended as a nano alternative.