Appearance
Nano Cheatsheet
Overview
GNU nano is a simple, user-friendly text editor for Unix and Linux systems. It's designed to be easy to use and provides a good alternative to more complex editors like Vim or Emacs.
Basic Usage
Starting Nano
bash
# Open nano
nano
# Open specific file
nano filename.txt
# Open file at specific line
nano +10 filename.txt
# Open file in read-only mode
nano -v filename.txt
# Open with line numbers
nano -l filename.txt
# Open with syntax highlighting
nano -Y python script.py
Command Line Options
bash
-A, --smarthome # Enable smart home key
-B, --backup # Save backups of existing files
-C, --backupdir=DIR # Directory for saving backup files
-D, --boldtext # Use bold text instead of reverse video
-E, --tabstospaces # Convert typed tabs to spaces
-F, --multibuffer # Enable multiple file buffers
-G, --locking # Use vim-style file locking
-H, --historylog # Log search and replace strings
-I, --ignorercfiles # Don't look at nanorc files
-J, --guidestripe=NUM # Show guide stripe at column NUM
-K, --rawsequences # Fix numeric keypad key confusion
-L, --nonewlines # Don't add newlines to file ends
-M, --trimblanks # Trim trailing whitespace when saving
-N, --noconvert # Don't convert files from DOS/Mac format
-O, --morespace # Use one more line for editing
-P, --positionlog # Log and read location of cursor position
-Q, --quotestr=STR # Quoting string for email-style quoting
-R, --restricted # Restricted mode
-S, --smooth # Smooth scrolling
-T, --tabsize=NUM # Set width of a tab to NUM columns
-U, --quickblank # Do quick statusbar blanking
-V, --version # Print version information and exit
-W, --wordbounds # Detect word boundaries more accurately
-X, --wordchars=STR # Which characters are word parts
-Y, --syntax=NAME # Syntax definition to use for coloring
-Z, --zap # Let Bsp and Del erase a marked region
-a, --atblanks # When soft-wrapping, do it at whitespace
-b, --breaklonglines # Automatically hard-wrap overlong lines
-c, --constantshow # Constantly show cursor position
-d, --rebinddelete # Fix Backspace/Delete confusion problem
-e, --emptyline # Keep the line below the title bar empty
-f, --rcfile=FILE # Use only this file for configuring nano
-g, --showcursor # Show cursor in file browser
-h, --help # Show help message and exit
-i, --autoindent # Automatically indent new lines
-j, --jumpyscrolling # Scroll by half-screens, not by lines
-k, --cutfromcursor # Cut from cursor to end of line
-l, --linenumbers # Show line numbers in front of the text
-m, --mouse # Enable mouse support
-n, --noread # Do not read the file (only write it)
-o, --operatingdir=DIR # Set operating directory
-p, --preserve # Preserve XON (^Q) and XOFF (^S) keys
-q, --indicator # Show a position+portion indicator
-r, --fill=NUM # Set hard-wrap point at column NUM
-s, --speller=PROG # Enable alternate speller
-t, --saveonexit # Save changes on exit, don't prompt
-u, --unix # Save a file by default in Unix format
-v, --view # View mode (read-only)
-w, --nowrap # Don't hard-wrap long lines
-x, --nohelp # Don't show the two help lines
-y, --afterends # Make Ctrl+Right stop at word ends
-z, --suspend # Enable suspension
Navigation
Basic Movement
Arrow keys # Move cursor
Ctrl+A # Go to beginning of line
Ctrl+E # Go to end of line
Ctrl+Y # Go to previous page
Ctrl+V # Go to next page
Ctrl+_ # Go to line and column number
Alt+G # Go to line number
Alt+] # Go to matching bracket
Advanced Navigation
Ctrl+P # Previous line
Ctrl+N # Next line
Ctrl+F # Forward one character
Ctrl+B # Backward one character
Alt+Space # Forward one word
Ctrl+Space # Backward one word
Alt+( # Go to beginning of paragraph
Alt+) # Go to end of paragraph
Editing
Basic Editing
Ctrl+K # Cut current line
Ctrl+U # Paste (uncut)
Ctrl+6 # Mark text (start selection)
Alt+6 # Copy marked text
Ctrl+K # Cut marked text
Alt+U # Undo last operation
Alt+E # Redo last undone operation
Ctrl+D # Delete character under cursor
Ctrl+H # Delete character before cursor
Advanced Editing
Alt+3 # Comment/uncomment line
Alt+} # Indent marked text
Alt+{ # Unindent marked text
Ctrl+T # Execute command
Alt+T # Cut from cursor to end of file
Alt+J # Justify paragraph
Alt+B # Backward search
Alt+W # Forward search
Ctrl+\ # Replace text
Search and Replace
Search
Ctrl+W # Search (Where is)
Alt+W # Search next occurrence
Alt+Q # Search previous occurrence
Ctrl+Q # Start backward search
Replace
Ctrl+\ # Search and replace
Alt+R # Replace in selection
Search Options
M-C # Case sensitive search
M-R # Regular expression search
M-B # Backward search
M-W # Whole word search
File Operations
File Management
Ctrl+O # Write out (save) file
Ctrl+R # Read file (insert file)
Ctrl+X # Exit nano
Ctrl+G # Get help
Ctrl+C # Show cursor position
Multiple Files
Alt+< # Switch to previous file
Alt+> # Switch to next file
Ctrl+T # To Files (file browser)
Selection and Copying
Text Selection
Ctrl+6 # Start marking text
Alt+A # Mark all text
Ctrl+K # Cut marked text
Alt+6 # Copy marked text without cutting
Ctrl+U # Paste text
Advanced Selection
Alt+Shift+Arrow # Select text with arrow keys
Ctrl+6 + movement # Mark text while moving
Configuration
Configuration File (.nanorc)
bash
# Create/edit configuration file
nano ~/.nanorc
# System-wide configuration
/etc/nanorc
Common Configuration Options
bash
# Show line numbers
set linenumbers
# Enable mouse support
set mouse
# Set tab size
set tabsize 4
# Convert tabs to spaces
set tabstospaces
# Enable auto-indentation
set autoindent
# Enable soft wrapping
set softwrap
# Show whitespace
set whitespace
# Enable syntax highlighting
include "/usr/share/nano/*.nanorc"
# Set backup directory
set backupdir "~/.nano/backups"
# Enable backups
set backup
# Smooth scrolling
set smooth
# Show cursor position
set constantshow
# Enable suspension with Ctrl+Z
set suspend
# Trim trailing whitespace
set trimblanks
# Use bold text
set boldtext
# Show guide stripe at column 80
set guidestripe 80
Syntax Highlighting
bash
# Enable syntax highlighting for specific file types
syntax "python" "\.py$"
color blue "def |class |import |from "
color red "".*""
color green "#.*$"
# Include all available syntax files
include "/usr/share/nano/*.nanorc"
# Custom syntax highlighting
syntax "myconfig" "\.conf$|\.config$"
color red "^[[:space:]]*[^=]*="
color blue "=.*$"
color green "^[[:space:]]*#.*$"
Key Bindings
Default Key Bindings
^G Get Help ^O Write Out ^W Where Is ^K Cut Text
^X Exit ^R Read File ^\ Replace ^U Paste Text
^J Justify ^T To Spell ^C Cur Pos ^_ Go To Line
Custom Key Bindings
bash
# In .nanorc file
bind ^S savefile main
bind ^Q exit main
bind ^F whereis main
bind ^H help main
bind M-U undo main
bind M-R redo main
Spell Checking
Built-in Spell Checker
Ctrl+T # Invoke spell checker
External Spell Checker
bash
# Use aspell
nano -s aspell filename.txt
# Use ispell
nano -s ispell filename.txt
# Configure in .nanorc
set speller "aspell -x -c"
Multiple Buffers
Buffer Management
Alt+< # Previous buffer
Alt+> # Next buffer
Ctrl+T # File browser
Opening Multiple Files
bash
# Open multiple files
nano file1.txt file2.txt file3.txt
# Enable multibuffer mode
nano -F file1.txt file2.txt
Advanced Features
Regular Expressions
bash
# Enable regex in search/replace
Alt+R (during search)
# Common regex patterns
. # Any character
* # Zero or more of preceding
+ # One or more of preceding
? # Zero or one of preceding
^ # Beginning of line
$ # End of line
[abc] # Any of a, b, or c
[^abc] # Not a, b, or c
\d # Digit
\w # Word character
\s # Whitespace
Macros
bash
# Nano doesn't have built-in macros, but you can:
# 1. Use external tools
# 2. Create shell scripts
# 3. Use sed/awk for repetitive tasks
Backup and Recovery
bash
# Enable backups in .nanorc
set backup
set backupdir "~/.nano/backups"
# Backup files are created with ~ suffix
# Original: file.txt
# Backup: file.txt~
Tips and Tricks
Productivity Tips
Ctrl+A, Ctrl+K # Cut entire line quickly
Ctrl+6, Ctrl+E, Alt+6 # Copy entire line
Alt+3 # Comment/uncomment (if configured)
Ctrl+W, Ctrl+R # Search and replace workflow
Ctrl+C # Check cursor position and file stats
Useful Combinations
bash
# Quick save and exit
Ctrl+O, Enter, Ctrl+X
# Select all and copy
Alt+A, Alt+6
# Go to specific line
Ctrl+_, line_number, Enter
# Search for text and replace
Ctrl+W, search_term, Enter, Ctrl+\, replacement, Enter
Working with Large Files
bash
# Open large files efficiently
nano -v largefile.txt # Read-only mode
# Use line numbers for navigation
nano -l largefile.txt
# Jump to specific line
nano +1000 largefile.txt
Troubleshooting
Common Issues
bash
# Terminal issues
export TERM=xterm-256color
# Key binding conflicts
# Check terminal settings
stty -a
# Permission issues
sudo nano /etc/hosts
# Encoding issues
nano -T 4 file.txt # Set tab width
Recovery
bash
# Recover unsaved changes
# Nano creates .save files for unsaved work
ls -la *.save
# Restore from backup
cp file.txt~ file.txt
Comparison with Other Editors
Nano vs Vim
Nano:
+ Easy to learn
+ Intuitive key bindings
+ Good for beginners
- Limited advanced features
- Less efficient for complex editing
Vim:
+ Powerful editing capabilities
+ Highly customizable
+ Modal editing
- Steep learning curve
- Complex key bindings
Nano vs Emacs
Nano:
+ Simple and lightweight
+ Quick startup
+ Easy configuration
- Limited extensibility
- Fewer features
Emacs:
+ Highly extensible
+ Rich feature set
+ Powerful customization
- Complex interface
- Resource intensive
Resources
- Official Documentation: nano-editor.org
- Manual Page:
man nano
- Help:
nano --help
orCtrl+G
within nano - Configuration Examples:
/usr/share/doc/nano/examples/