# nano — The Simple Terminal Text Editor

> Practical guide to nano — edit files in the terminal quickly and without a learning curve, the beginner-friendly editor on every Linux.

Source: https://www.jpkc.com/db/en/cheatsheets/files-text/nano/

<!-- PROSE:intro -->
nano is the simple, beginner-friendly text editor for the terminal: it ships on virtually every Linux system and is deliberately built so you can start editing without a steep learning curve. The most important commands are always shown in the key bar at the bottom, where `^` stands for the Ctrl key and `M-` for the Alt/Meta key. Unlike vim there are no modes – you start typing right away and save with `Ctrl+O`, quit with `Ctrl+X`. This guide walks you through the key bindings and `.nanorc` settings that let you work in nano quickly and comfortably.
<!-- PROSE:intro:end -->

## Opening Files

`nano <file>` — Open a file for editing (creates it if it doesn't exist).

```bash
nano config.yaml
```

`nano +<line> <file>` — Open a file and jump to a specific line number.

```bash
nano +42 script.sh
```

`nano +<line>,<col> <file>` — Open a file and jump to a specific line and column.

```bash
nano +10,5 config.php
```

`nano -B <file>` — Create a backup of the file before editing (~filename~).

```bash
nano -B /etc/nginx/nginx.conf
```

`nano -R <file>` — Open a file in read-only (restricted) mode.

```bash
nano -R /etc/passwd
```

`nano -l <file>` — Show line numbers in the left margin.

```bash
nano -l script.py
```

`nano -m <file>` — Enable mouse support for clicking and scrolling.

```bash
nano -m document.txt
```

`nano -i <file>` — Enable auto-indentation.

```bash
nano -i main.go
```

`nano -Y <syntax> <file>` — Force a specific syntax highlighting language.

```bash
nano -Y php config.inc
```

## Saving & Exiting

`Ctrl+O` — Write Out (save) the current file. Press Enter to confirm the filename.

```bash
Ctrl+O → Enter
```

`Ctrl+X` — Exit nano. Prompts to save if there are unsaved changes.

```bash
Ctrl+X → Y → Enter
```

`Ctrl+X → N` — Exit without saving changes.

```bash
Ctrl+X → N
```

`Ctrl+O → new_filename → Enter` — Save As: type a new filename when prompted by Write Out.

```bash
Ctrl+O → backup.conf → Enter
```

## Navigation

`Ctrl+A / Ctrl+E` — Jump to the beginning / end of the current line.

```bash
Ctrl+A
```

`Ctrl+Y / Ctrl+V` — Page Up / Page Down.

```bash
Ctrl+V
```

`Alt+\ / Alt+/` — Jump to the first / last line of the file.

```bash
Alt+\
```

`Ctrl+_ (Ctrl+Shift+-)` — Go to a specific line number (and optionally column).

```bash
Ctrl+_ → 42 → Enter
```

`Alt+G` — Go to line number (alternative shortcut).

```bash
Alt+G → 100 → Enter
```

`Ctrl+Space / Alt+Space` — Move forward / backward one word.

```bash
Ctrl+Space
```

`Ctrl+C` — Show the current cursor position (line, column, character).

```bash
Ctrl+C
```

## Editing

`Ctrl+K` — Cut the current line (or selected text) to the cutbuffer.

```bash
Ctrl+K
```

`Ctrl+U` — Paste (uncut) the cutbuffer at the cursor position.

```bash
Ctrl+U
```

`Alt+6` — Copy the current line (or selected text) without cutting it.

```bash
Alt+6
```

`Ctrl+K (multiple)` — Cut consecutive lines — they accumulate in the cutbuffer.

```bash
Ctrl+K Ctrl+K Ctrl+K (cuts 3 lines)
```

`Alt+T` — Cut from the cursor to the end of the file.

```bash
Alt+T
```

`Ctrl+J` — Justify (reflow) the current paragraph.

```bash
Ctrl+J
```

`Alt+U` — Undo the last action.

```bash
Alt+U
```

`Alt+E` — Redo the last undone action.

```bash
Alt+E
```

`Ctrl+\` — Search and replace.

```bash
Ctrl+\ → old → Enter → new → Enter → A (replace all)
```

`Alt+3` — Toggle comment/uncomment the current line.

```bash
Alt+3
```

`Tab / Shift+Tab` — Indent / unindent the current line or selected lines.

```bash
Select lines → Tab
```

## Search

`Ctrl+W` — Search forward for a string.

```bash
Ctrl+W → search term → Enter
```

`Alt+W` — Repeat the last search (find next).

```bash
Alt+W
```

`Ctrl+W → Alt+R` — Switch to regex search mode.

```bash
Ctrl+W → Alt+R → [0-9]+ → Enter
```

`Ctrl+W → Alt+C` — Toggle case sensitivity in search.

```bash
Ctrl+W → Alt+C
```

`Ctrl+W → Alt+B` — Search backwards.

```bash
Ctrl+W → Alt+B → term → Enter
```

`Ctrl+\` — Search and replace. Options: Y (yes), N (no), A (all).

```bash
Ctrl+\ → http → Enter → https → Enter → A
```

## Selection (Mark)

`Alt+A` — Toggle mark (start/stop text selection). Move cursor to select.

```bash
Alt+A → move → Ctrl+K (cut selection)
```

`Ctrl+6` — Set mark at cursor (alternative to Alt+A).

```bash
Ctrl+6
```

`Alt+A → Ctrl+K` — Select text and cut it.

```bash
Alt+A → select → Ctrl+K
```

`Alt+A → Alt+6` — Select text and copy it (without cutting).

```bash
Alt+A → select → Alt+6
```

## File Operations

`Ctrl+R` — Insert the contents of another file at the cursor position.

```bash
Ctrl+R → header.html → Enter
```

`Ctrl+R → Ctrl+T` — Open a file browser to select a file to insert.

```bash
Ctrl+R → Ctrl+T
```

`Ctrl+T` — Execute a command and insert its output (or invoke spell checker).

```bash
Ctrl+T → date → Enter
```

`Alt+D` — Show word, line, and character count of the file (or selection).

```bash
Alt+D
```

## Configuration (~/.nanorc)

`set linenumbers` — Always show line numbers.

```bash
set linenumbers
```

`set autoindent` — Automatically indent new lines to match the previous line.

```bash
set autoindent
```

`set tabsize <n>` — Set the displayed width of a tab character.

```bash
set tabsize 4
```

`set tabstospaces` — Convert tabs to spaces when typing.

```bash
set tabstospaces
```

`set mouse` — Enable mouse support.

```bash
set mouse
```

`set softwrap` — Enable soft line wrapping (visual only, no newlines added).

```bash
set softwrap
```

`set backup` — Always create backup files when saving.

```bash
set backup
set backupdir ~/.nano-backups
```

`include /usr/share/nano/*.nanorc` — Include syntax highlighting files for all supported languages.

```bash
include /usr/share/nano/*.nanorc
```

<!-- PROSE:outro -->
## Conclusion

nano is the right choice when you want to tweak a config file quickly or jot down a short text without having to learn an editor first: no modes, the most important shortcuts always visible in the footer, and available instantly on almost any system. Above all, remember `Ctrl+O` (save) and `Ctrl+X` (quit) – on exit nano asks about unsaved changes by itself, so you don't lose anything by accident. If you want more comfort, enable line numbers, auto-indent and syntax highlighting in your `~/.nanorc`. For heavier editing or working efficiently with large files, it's worth moving up to vim later.

## Further Reading

- [GNU nano – official site](https://www.nano-editor.org/) – the project home page with the manual and all options
- [nano(1) manual page](https://man7.org/linux/man-pages/man1/nano.1.html) – the Linux manual page for nano
<!-- PROSE:outro:end -->

## Related Commands

- [vim](https://www.jpkc.com/db/en/cheatsheets/files-text/vim/) – powerful modal editor for advanced editing
- [less](https://www.jpkc.com/db/en/cheatsheets/files-text/less/) – pager for viewing files without editing them
- [mc](https://www.jpkc.com/db/en/cheatsheets/files-text/mc/) – terminal file manager with the built-in editor mcedit

