Saltar a contenido

Nano Cheatsheet

Sinopsis

GNU nano es un editor de texto sencillo y fácil de usar para sistemas Unix y Linux. Está diseñado para ser fácil de usar y ofrece una buena alternativa a editores más complejos como Vim o Emacs.

Uso básico

Nano

# 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

Opciones de línea de mando

-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

Movimiento básico

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
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

Edición

Edición básica

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

Edición avanzada

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

Búsqueda y sustitución

Búsqueda

Ctrl+W        # Search (Where is)
Alt+W         # Search next occurrence
Alt+Q         # Search previous occurrence
Ctrl+Q        # Start backward search

Sustitución

Ctrl+\        # Search and replace
Alt+R         # Replace in selection

Opciones de búsqueda

M-C           # Case sensitive search
M-R           # Regular expression search
M-B           # Backward search
M-W           # Whole word search

Operaciones de archivo

Administración de archivos

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

Múltiples archivos

Alt+<         # Switch to previous file
Alt+>         # Switch to next file
Ctrl+T        # To Files (file browser)

Selección y copia

Selección de texto

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

Selección Avanzada

Alt+Shift+Arrow # Select text with arrow keys
Ctrl+6 + movement # Mark text while moving

Configuración

Archivo de configuración (.nanorc)

# Create/edit configuration file
nano ~/.nanorc

# System-wide configuration
/etc/nanorc

Opciones de configuración común

# 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

Sintax Highlighting

# 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:]]*#.*$"

Cadenas clave

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

Cadenas de clave personalizadas

# 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

Comprobación de la función

Comprobador de carga incorporado

Ctrl+T        # Invoke spell checker

Comprobador de carga externa

# Use aspell
nano -s aspell filename.txt

# Use ispell
nano -s ispell filename.txt

# Configure in .nanorc
set speller "aspell -x -c"

Múltiples amortiguadores

Buffer Management

Alt+<         # Previous buffer
Alt+>         # Next buffer
Ctrl+T        # File browser

Apertura de múltiples archivos

# Open multiple files
nano file1.txt file2.txt file3.txt

# Enable multibuffer mode
nano -F file1.txt file2.txt

Características avanzadas

Expresiones periódicas

# 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

# 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

Copia de seguridad y recuperación

# Enable backups in .nanorc
set backup
set backupdir "~/.nano/backups"

# Backup files are created with ~ suffix
# Original: file.txt
# Backup: file.txt~

Consejos y trucos

Consejos de productividad

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

Combinaciones útiles

# 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

Trabajando con archivos grandes

# 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

Solución de problemas

Cuestiones comunes

# 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

Recuperación

# Recover unsaved changes
# Nano creates .save files for unsaved work
ls -la *.save

# Restore from backup
cp file.txt~ file.txt

Comparación con otros editores

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

Recursos

  • ** Documentación oficial**: nano-editor.org
  • ** Página manual**: man nano
  • Ayuda: nano --help o Ctrl+G
  • ** Ejemplos de configuración**: /usr/share/doc/nano/examples/_