File Handling
| Key | Action |
Ctrl + S | Save current file |
Ctrl + O | Offer to write file ("Save as") |
Ctrl + R | Insert a file into current one |
Ctrl + X | Close buffer, exit from nano |
Editing
| Key | Action |
Ctrl + K | Cut current line into cutbuffer |
Alt + 6 | Copy current line into cutbuffer |
Ctrl + U | Paste contents of cutbuffer |
Alt + T | Cut until end of buffer |
Ctrl + ] | Complete current word |
Alt + 3 | Comment/uncomment line/region |
Alt + U | Undo last action |
Alt + E | Redo last undone action |
Search and Replace
| Key | Action |
Ctrl + Q | Start backward search |
Ctrl + W | Start forward search |
Alt + Q | Find next occurrence backward |
Alt + W | Find next occurrence forward |
Alt + R | Start a replacing session |
Deletion
| Key | Action |
Ctrl + H | Delete character before cursor |
Ctrl + D | Delete character under cursor |
Alt + Bsp | Delete word to the left |
Ctrl + Del | Delete word to the right |
Alt + Del | Delete current line |
Operations & Macros
| Key | Action |
Ctrl + T | Execute some command |
Ctrl + J | Justify paragraph or region |
Alt + J | Justify entire buffer |
Alt + B | Run a syntax check |
Alt + F | Run a formatter/fixer/arranger |
Alt + : | Start/stop recording of macro |
Alt + ; | Replay macro |
Moving Around (Navigation)
| Key | Action |
Ctrl + B | One character backward |
Ctrl + F | One character forward |
Ctrl + ← | One word backward |
Ctrl + → | One word forward |
Ctrl + A | To start of line |
Ctrl + E | To end of line |
Ctrl + P | One line up |
Ctrl + N | One line down |
Ctrl + ↑ | To previous block |
Ctrl + ↓ | To next block |
Ctrl + Y | One page up |
Ctrl + V | One page down |
Alt + \ | To top of buffer |
Alt + / | To end of buffer |
Special Movement & Buffers
| Key | Action |
Alt + G | Go to specified line |
Alt + ] | Go to complementary bracket |
Alt + ↑ | Scroll viewport up |
Alt + ↓ | Scroll viewport down |
Alt + < | Switch to preceding buffer |
Alt + > | Switch to succeeding buffer |
Information & Various
| Key | Action |
Ctrl + C | Report cursor position |
Alt + D | Report line/word/character count |
Ctrl + G | Display help text |
Alt + A | Turn the mark on/off (selection mode) |
Tab | Indent marked region |
Shift + Tab | Unindent marked region |
Alt + N | Turn line numbers on/off |
Alt + P | Turn visible whitespace on/off |
Alt + V | Enter next keystroke verbatim |
Ctrl + L | Refresh the screen |
Ctrl + Z | Suspend nano |
Configuration
Configuration is typically stored in ~/.nanorc.
set linenumbers
set tabsize 4
set autoindent
Advanced Startup Flags
You can launch nano with these flags to change its behavior for a single session without editing your ~/.nanorc file.
| Flag | Action |
nano -m | Enable mouse support (click to place cursor). |
nano -S | Enable soft wrapping (long lines wrap visually, not physically). |
nano -B | Create backup files (saves filename~ before editing). |
nano -v | View-only mode (read-only, prevents accidental saves). |
nano +[line],[col] | Open file at a specific line and column (e.g., nano +50,2 index.js). |
Power-User Tricks
Regular Expression Search
- Press
Ctrl + W (Search).
- Press
Alt + R to toggle Regular Expressions on/off.
- Type your regex and hit
Enter.
Run External Commands & Insert Output
You can run a bash command (like ls or date) and paste its output directly into your text file:
- Press
Ctrl + T (Execute command).
- Type the shell command (e.g.,
date or ls -la).
- Press
Enter to insert the output at your cursor's current position.
Soft Line Wrapping
By default, nano inserts hard line breaks if a line gets too long. To toggle "Soft Wrapping" (visually wrapping text to fit the window without adding actual line break characters):
- Press
Alt + $ while in the editor.
Mouse Support
If you get tired of using arrow keys to navigate large files, you can enable your mouse:
- Press
Alt + M to toggle mouse support. You can now click anywhere to move your cursor or use the scroll wheel.
Advanced Configuration (~/.nanorc)
To make nano behave more like a modern code editor (VS Code, Sublime), add these to your ~/.nanorc file:
set linenumbers
set tabsize 4
set tabstospaces
set mouse
set softwrap
include "/usr/share/nano/*.nanorc"