Linux

nano

Simple, easy-to-use command line text editor.

#linux #editor #text

File Handling

KeyAction
Ctrl + SSave current file
Ctrl + OOffer to write file ("Save as")
Ctrl + RInsert a file into current one
Ctrl + XClose buffer, exit from nano

Editing

KeyAction
Ctrl + KCut current line into cutbuffer
Alt + 6Copy current line into cutbuffer
Ctrl + UPaste contents of cutbuffer
Alt + TCut until end of buffer
Ctrl + ]Complete current word
Alt + 3Comment/uncomment line/region
Alt + UUndo last action
Alt + ERedo last undone action

Search and Replace

KeyAction
Ctrl + QStart backward search
Ctrl + WStart forward search
Alt + QFind next occurrence backward
Alt + WFind next occurrence forward
Alt + RStart a replacing session

Deletion

KeyAction
Ctrl + HDelete character before cursor
Ctrl + DDelete character under cursor
Alt + BspDelete word to the left
Ctrl + DelDelete word to the right
Alt + DelDelete current line

Operations & Macros

KeyAction
Ctrl + TExecute some command
Ctrl + JJustify paragraph or region
Alt + JJustify entire buffer
Alt + BRun a syntax check
Alt + FRun a formatter/fixer/arranger
Alt + :Start/stop recording of macro
Alt + ;Replay macro

Moving Around (Navigation)

KeyAction
Ctrl + BOne character backward
Ctrl + FOne character forward
Ctrl + ←One word backward
Ctrl + →One word forward
Ctrl + ATo start of line
Ctrl + ETo end of line
Ctrl + POne line up
Ctrl + NOne line down
Ctrl + ↑To previous block
Ctrl + ↓To next block
Ctrl + YOne page up
Ctrl + VOne page down
Alt + \To top of buffer
Alt + /To end of buffer

Special Movement & Buffers

KeyAction
Alt + GGo 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

KeyAction
Ctrl + CReport cursor position
Alt + DReport line/word/character count
Ctrl + GDisplay help text
Alt + ATurn the mark on/off (selection mode)
TabIndent marked region
Shift + TabUnindent marked region
Alt + NTurn line numbers on/off
Alt + PTurn visible whitespace on/off
Alt + VEnter next keystroke verbatim
Ctrl + LRefresh the screen
Ctrl + ZSuspend 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.

FlagAction
nano -mEnable mouse support (click to place cursor).
nano -SEnable soft wrapping (long lines wrap visually, not physically).
nano -BCreate backup files (saves filename~ before editing).
nano -vView-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

  1. Press Ctrl + W (Search).
  2. Press Alt + R to toggle Regular Expressions on/off.
  3. 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:

  1. Press Ctrl + T (Execute command).
  2. Type the shell command (e.g., date or ls -la).
  3. 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:

# Enable line numbers by default
set linenumbers

# Set tab size to 4 spaces and convert tabs to spaces
set tabsize 4
set tabstospaces

# Enable mouse support by default
set mouse

# Enable soft line wrapping by default
set softwrap

# -----------------------------------------------------
# Enable Syntax Highlighting for all supported languages
# (Path may vary slightly depending on your OS/Distro)
# -----------------------------------------------------
include "/usr/share/nano/*.nanorc"