Nano Feuille de chaleur
Aperçu général
GNU nano est un éditeur de texte simple et convivial pour les systèmes Unix et Linux. Il est conçu pour être facile à utiliser et offre une bonne alternative aux éditeurs plus complexes comme Vim ou Emacs.
Utilisation de base
Démarrage 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
Options de ligne de commande
-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
### Mouvement de base
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
### Navigation avancée
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
## Édition
### Édition de base
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
### Édition avancée
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
## Recherche et remplacement
### Rechercher
Ctrl+W # Search (Where is) Alt+W # Search next occurrence Alt+Q # Search previous occurrence Ctrl+Q # Start backward search
### Remplacer
Ctrl+\ # Search and replace Alt+R # Replace in selection
### Options de recherche
M-C # Case sensitive search M-R # Regular expression search M-B # Backward search M-W # Whole word search
## Opérations de fichiers
### Gestion de fichiers
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
### Fichiers multiples
Alt+< # Switch to previous file Alt+> # Switch to next file Ctrl+T # To Files (file browser)
## Sélection et copie
### Sélection du texte
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
### Sélection avancée
Alt+Shift+Arrow # Select text with arrow keys Ctrl+6 + movement # Mark text while moving
## Configuration
### Fichier de configuration (.nanorc)
```bash
# Create/edit configuration file
nano ~/.nanorc
# System-wide configuration
/etc/nanorc
Options communes de configuration
# 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
Syntaxe Mise en évidence
# 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:]]*#.*$"
Reliure des clés
Reliure par défaut des clés
^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
Reliures de clés personnalisées
# 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
Vérification orthographique
Vérificateur d'orthographe intégré
Ctrl+T # Invoke spell checker
Vérificateur d'orthographe externe
# Use aspell
nano -s aspell filename.txt
# Use ispell
nano -s ispell filename.txt
# Configure in .nanorc
set speller "aspell -x -c"
Plusieurs tampons
Gestion des tampons
Alt+< # Previous buffer
Alt+> # Next buffer
Ctrl+T # File browser
Ouverture de plusieurs fichiers
# Open multiple files
nano file1.txt file2.txt file3.txt
# Enable multibuffer mode
nano -F file1.txt file2.txt
Caractéristiques avancées
Expressions régulières
# 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
Sauvegarde et récupération
# Enable backups in .nanorc
set backup
set backupdir "~/.nano/backups"
# Backup files are created with ~ suffix
# Original: file.txt
# Backup: file.txt~
Conseils et astuces
Conseils en matière de productivité
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
Combinaisons utiles
# 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
Travailler avec les grands fichiers
# 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
Dépannage
Questions communes
# 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
Récupération
# Recover unsaved changes
# Nano creates .save files for unsaved work
ls -la *.save
# Restore from backup
cp file.txt~ file.txt
Comparaison avec d'autres éditeurs
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
Ressources
- Documentation officielle: [nano-editor.org] (LINK_1)
- ** Page manuelle** :
man nano
- Aide:
nano --help
ouCtrl+G
dans les nano - ** Exemples de configuration** :
/usr/share/doc/nano/examples/