| | |

LFCA 19 ๐Ÿง Editing Files with nano โ€” Basics

Editing a file on a Linux system often happens at the worst possible moment: a broken SSH config, a wrong hostname in /etc/hosts, a typo in an fstab entry that is blocking boot. You do not have a graphical editor, you may not have vim muscle memory yet, and the file needs one small change right now. This is the niche nano fills. It is a small, modeless text editor whose entire interface is visible on screen at all times โ€” the commands are printed at the bottom, the caret is already in the text, and nothing has to be learned before you can start typing. This chapter covers what nano is, why it is designed the way it is, how to open and save files, how to navigate and search, and the habits that make it a reliable tool rather than a crutch. It deliberately does not cover vim or sed โ€” those are separate chapters, and mixing them here would blur the point that nano is a specific tool with a specific strength.

Key point: nano is modeless โ€” typing always inserts text, arrow keys always move the cursor, and the shortcut bar is always visible. The essential commands are Ctrl+O to save, Ctrl+X to exit, Ctrl+W to search, and Ctrl+K / Ctrl+U to cut and paste lines. It ships in the base install of nearly every distribution and rescue image, which means it is the editor most likely to be available when a system is broken. Its limitations โ€” no macros, no splits, no scripting โ€” are real, but they do not matter for the class of edits it is meant for.


Why nano exists, and what problem it solves

The history matters because it explains the design. The original Unix editor was ed, a line editor with no full-screen display, then vi (and later vim), which added a full-screen modal interface but kept a command language that must be memorized. For experienced users that language is a strength. For someone who needs to change one line in one file on one afternoon, it is a barrier.

nano began as a clone of pico, the editor bundled with the Pine email client, and its goal was explicitly the opposite of vi: be immediately usable, require no manual, and never hide what the keys do. That is why the shortcut bar exists. It is not decoration โ€” it is the editor’s answer to “how do I save?” without documentation.

Why the shortcut bar is the whole point. On a 24-line terminal, two lines are permanently spent on hints. That is a real cost โ€” fewer lines of the file visible โ€” and nano accepts it deliberately. The trade is: you always know how to save, quit, search, and cut. Compare that with vim, where the same information is one :help away but not on screen. The design says: this editor is for people who do not want to remember commands, and it commits to that fully.

Why modeless editing is easier to reason about. In a modeless editor, every keystroke has exactly one meaning: the character you typed gets inserted. There is no state to track, no “am I in the right mode?” question, no accidental dd that deletes a line because you forgot to press i first. This simplicity is why nano is the right first editor and a reasonable permanent choice for configuration work, even for people who later learn vim for code.

Why nano is still worth learning even if you plan to use vim: Because it is what you will find when vim is not installed. Minimal containers, Alpine images, recovery shells, and freshly installed systems often ship nano but not vim. The editor you know in an emergency matters more than the editor you prefer.


Opening files and the basic screen

The command is nano followed by a path. If the file exists, it opens. If it does not exist, nano opens an empty buffer with that filename and creates the file when you save.

$ nano /etc/hosts

The screen that appears has three regions. The top line is a title bar showing the version and the filename โ€” and an asterisk appears next to the filename once you have made unsaved changes. The middle is the file’s contents, with the cursor placed in it. The bottom two lines are the shortcut bar, showing the currently relevant key combinations in the form ^O Write Out, where ^ means Ctrl.

Opening at a specific line. When you know the line number you need, +N jumps straight there.

$ nano +42 /etc/ssh/sshd_config

This opens the file with the cursor already on line 42. It is useful when a compiler error, a grep -n result, or a log message has told you exactly where the problem is, and you want to avoid scrolling.

Opening read-only. If you only want to inspect a file and want a guard against accidental edits, -v opens it in view mode.

$ nano -v /etc/sudoers

View mode blocks all modifications. It is a small safety measure, and it matters most on files like sudoers where a stray keystroke can lock you out of administrative access.

Why the title bar asterisk is a habit worth forming. Before you Ctrl+X, glance at the title bar. If there is an asterisk, there are unsaved changes, and exiting will prompt you. If there is no asterisk, the buffer matches the file on disk. This one-second check prevents the “did I save?” uncertainty that leads people to exit, reopen, and re-read the whole file.


Saving, exiting, and the three-way prompt

Ctrl+O writes the buffer to disk. Ctrl+X exits. When the buffer has unsaved changes, Ctrl+X does not exit immediately โ€” it asks.

Save modified buffer?
 Y Yes
 N No
^C Cancel

Pressing Y proceeds to the filename prompt, where Enter accepts the existing name and typing a new name performs a save-as. Pressing N discards the changes and exits. Pressing Ctrl+C cancels the exit entirely and returns you to the editor with the buffer intact. That third option is the one people forget: if you hit Ctrl+X by accident, Ctrl+C puts you back.

Why the save-as path is useful. Ctrl+O followed by editing the filename is how you write a copy without leaving the editor. This matters when you are editing a system file and want to keep the original untouched โ€” open /etc/nginx/nginx.conf, make your edits, and save as /etc/nginx/nginx.conf.new, then validate and move it into place. It is a disciplined pattern for risky files, and nano supports it without ceremony.

Why Ctrl+O before Ctrl+X is not always necessary. Many people save and then exit as two habits. In practice, Ctrl+X with a modified buffer prompts to save anyway, so the sequence is Ctrl+X, Y, Enter. The two-step Ctrl+O then Ctrl+X is clearer when you want to confirm the save succeeded before leaving, and it is the habit most tutorials teach because it makes the save explicit.

Why the cancel option matters more than it looks: The Ctrl+C in the exit prompt is the only way to abort an exit in progress. Without knowing it, a user who fat-fingers Ctrl+X on a file they were still reading may press N to “get back” โ€” which discards their edits. The prompt is not a trap, but the third option is the escape hatch, and it is worth committing to memory.


Navigation and searching

Arrow keys move the cursor one character or one line at a time. Home and End go to the start and end of the current line. Page Up and Page Down move a screenful. These are the same as in any graphical editor and require no learning.

Searching with Ctrl+W. This is the shortcut that turns nano from usable into genuinely useful. Ctrl+W opens a Search: prompt at the bottom. Type the pattern and press Enter; the cursor jumps to the first match after the current position. Alt+W repeats the search for the next occurrence. To search backward, Ctrl+W then Enter with an empty pattern repeats the last search.

Ctrl+W          โ†’  open search prompt
(type pattern)
Enter           โ†’  jump to first match
Alt+W           โ†’  find next occurrence

Jumping to a line with Ctrl+_. On most terminals this is Ctrl+Shift+Minus, though some keyboards and terminal emulators require Ctrl+_ directly or a different combination. When it works, it opens a Go To Line: prompt where you enter a number and press Enter. Combined with a line number from a compiler or a grep -n, this is faster than scrolling.

Why searching beats scrolling. A 500-line config file scrolled by hand takes a minute and invites missing the target. The same file searched with Ctrl+W and a distinctive fragment takes two seconds and lands exactly. The habit to build is: before scrolling, search.


Cut, paste, and selecting text

nano has a small but complete set of block operations, and they are centered on one idea: the cut buffer. Ctrl+K cuts the current line (or the selected region) into that buffer. Ctrl+U pastes the buffer at the cursor.

Ctrl+K   โ†’  cut current line (or selection)
Ctrl+U   โ†’  paste buffer

Moving a line. Cut and paste is the move operation. To move a line down two positions: Ctrl+K to cut it, move the cursor down two lines, Ctrl+U to paste. There is no dedicated “move line” command, but the cut/paste pair covers it.

Deleting a block of lines. Ctrl+K repeatedly cuts successive lines into the buffer, which means a fast way to delete five lines is Ctrl+K five times. The buffer holds the last cut content, so if you cut the wrong block, Ctrl+U restores it โ€” but only the most recent cut.

Selecting a region. Ctrl+^ (often Ctrl+6 or Ctrl+Shift+6 depending on the terminal) marks the start of a selection. Move the cursor to extend it, then Ctrl+K cuts the selected text or Alt+6 copies it. This is the mechanism for operating on part of a line rather than whole lines, and it is worth learning once you find yourself editing code or long configuration values.

Why the cut buffer is a single slot. nano keeps only one buffer, unlike vim‘s named registers. That means a second cut overwrites the first. It is a limitation, and the practical consequence is that complex rearrangement is done in stages rather than all at once. For the edits nano is designed for, a single buffer is enough.

Why Ctrl+U is worth remembering before you need it: The most common nano panic is cutting a line you did not mean to cut. The recovery is Ctrl+U immediately. People who do not know this re-type the line from memory, which is slower and error-prone. Learn the paste command before the cut command.


Configuration: making nano comfortable

nano reads ~/.nanorc at startup, and a handful of lines turn it from spartan to comfortable. The options that matter most are line numbers, automatic indentation, and syntax highlighting.

set linenumbers
set autoindent
set tabsize 4
include "/usr/share/nano/*.nanorc"

Line numbers make Ctrl+_ and compiler error messages directly usable โ€” you can see which line you are on. Autoindent carries indentation from the previous line, which is the difference between editing YAML and fighting it. The include line pulls in the distribution’s syntax highlighting definitions, which color comments, strings, and keywords and make a config file readable at a glance.

Why syntax highlighting is more than cosmetic. In a file like /etc/ssh/sshd_config, a mistyped directive with the wrong syntax is invisible in monochrome but obvious when keywords are colored and strings are not. Highlighting turns the editor into a light validator. It does not catch every mistake, but it catches the class of mistake that comes from not noticing which part of the line is a value and which is a directive.

Why set autoindent matters for YAML and Python. Both languages treat indentation as syntax. Without autoindent, every new line starts at column zero and must be manually indented, which is slow and error-prone. With it, the structure carries forward and editing stays sane. This is a one-line configuration change that materially improves the experience of editing the files most likely to break when indentation is wrong.


Complete Example Session

# ============================================
# PART 1: OPEN AND EDIT A FILE
# ============================================

# Create a test file
printf "server=localhost\nport=8080\n" > app.conf

# Open it
nano app.conf

# Inside nano:
#   Type: # edited by nano
#   Ctrl+O, Enter   โ†’ save
#   Ctrl+X          โ†’ exit

cat app.conf
# # edited by nano
# server=localhost
# port=8080

# ============================================
# PART 2: SEARCH INSIDE NANO
# ============================================

# Open a larger file
nano /etc/services

# Inside nano:
#   Ctrl+W          โ†’ search prompt
#   type: http
#   Enter           โ†’ jump to first match
#   Alt+W           โ†’ next match
#   Ctrl+X          โ†’ exit (no changes)

# ============================================
# PART 3: JUMP TO A LINE
# ============================================

nano +20 /etc/services

# Inside nano:
#   Cursor is on line 20
#   Title bar shows: GNU nano ... /etc/services
#   Ctrl+X to exit

# ============================================
# PART 4: CUT AND PASTE A LINE
# ============================================

printf "alpha\nbeta\ngamma\n" > order.txt

nano order.txt

# Inside nano:
#   Cursor on "alpha"
#   Ctrl+K          โ†’ cut "alpha"
#   Down, Down      โ†’ move to after "gamma"
#   Ctrl+U          โ†’ paste "alpha" here
#   Ctrl+O, Enter   โ†’ save
#   Ctrl+X          โ†’ exit

cat order.txt
# beta
# gamma
# alpha

# ============================================
# PART 5: SAVE AS A NEW FILE
# ============================================

nano app.conf

# Inside nano:
#   Make an edit
#   Ctrl+O
#   Backspace to clear filename
#   Type: app.conf.bak
#   Enter           โ†’ writes app.conf.bak
#   Ctrl+X          โ†’ exit

ls app.conf*
# app.conf  app.conf.bak

# ============================================
# PART 6: EXIT PROMPT AND CANCEL
# ============================================

nano order.txt

# Inside nano:
#   Type something
#   Ctrl+X          โ†’ "Save modified buffer?"
#   Ctrl+C          โ†’ cancel exit, back in editor
#   Ctrl+X
#   N               โ†’ discard changes, exit

cat order.txt
# beta
# gamma
# alpha

# ============================================
# PART 7: VIEW MODE
# ============================================

nano -v /etc/hostname
# Opens read-only; typing does nothing
# Ctrl+X to exit

# ============================================
# PART 8: CONFIGURE NANO
# ============================================

printf 'set linenumbers\nset autoindent\nset tabsize 4\n' > ~/.nanorc

nano app.conf
# Line numbers appear on the left
# Tab key inserts 4 spaces
# Ctrl+X to exit

# ============================================
# PART 9: SELECT AND CUT A REGION
# ============================================

printf "hello world\nfoo bar\n" > sel.txt

nano sel.txt

# Inside nano:
#   Cursor on "hello"
#   Ctrl+^          โ†’ mark selection start
#   Right, Right, Right, Right, Right  โ†’ select "hello"
#   Ctrl+K          โ†’ cut selection
#   Ctrl+O, Enter   โ†’ save
#   Ctrl+X          โ†’ exit

cat sel.txt
#  world
# foo bar

# ============================================
# PART 10: WHAT NOT TO DO
# ============================================

# Do NOT open a binary file
# nano /bin/ls       โ† shows garbage, wastes time

# Do NOT use nano for scripted bulk edits
# That is sed's job (next chapter)

# Do NOT edit /etc/sudoers without visudo
# nano /etc/sudoers  โ† syntax error can lock you out

Each part exercises a real nano workflow. Parts 1 through 5 cover the editing loop, parts 6 through 9 cover recovery and comfort, and part 10 names the boundaries where another tool is correct.


Quick Reference

Essential Keystrokes

KeysAction
Ctrl+OSave (Write Out)
Ctrl+XExit
Ctrl+WSearch
Alt+WFind next
Ctrl+KCut line or selection
Ctrl+UPaste
Ctrl+^Mark selection start
Ctrl+_Go to line
Ctrl+CCancel current prompt
Ctrl+GHelp

Navigation

KeysAction
ArrowsMove one character/line
Home / EndStart / end of line
Page Up / Page DownScreen up / down
Ctrl+A / Ctrl+EStart / end of line
Ctrl+Y / Ctrl+VPage up / down
Alt+\First line of file
Alt+/Last line of file

Command-Line Options

OptionEffect
nano fileOpen or create
nano +N fileOpen at line N
nano -v fileView mode (read-only)
nano -w fileDisable wrapping
nano -l fileShow line numbers
nano -m fileEnable mouse

Exit Prompt Choices

ChoiceEffect
YSave, then prompt for filename
NDiscard changes and exit
Ctrl+CCancel exit, stay in editor

~/.nanorc Options

OptionEffect
set linenumbersShow line numbers
set autoindentCarry indentation forward
set tabsize 4Tab width
set mouseEnable mouse support
include "..."Load syntax highlighting

When to Use nano

SituationReason
Quick config editNo learning curve
Minimal or rescue systemUsually installed
First editor for beginnersShortcuts visible
Editing on unfamiliar serverPredictable behavior
Single-file, human-scale changeFits the tool

When Not to Use nano

SituationBetter tool
Large-scale code workvim or an IDE
Bulk find-and-replacesed
Editing sudoersvisudo
Binary filesxxd, hexdump
Version-controlled editsYour VCS’s workflow

Best Practices

โœ… Do This:

# Open at the line you need
nano +42 /etc/ssh/sshd_config                                 # โœ…

# Search before scrolling
# Inside nano: Ctrl+W, type pattern, Enter                     # โœ…

# Save explicitly and confirm
# Inside nano: Ctrl+O, Enter, then Ctrl+X                     # โœ…

# Use view mode for sensitive files
nano -v /etc/sudoers                                          # โœ…

# Keep a copy before editing a system file
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo nano /etc/nginx/nginx.conf                               # โœ…

# Enable line numbers and highlighting
printf 'set linenumbers\ninclude "/usr/share/nano/*.nanorc"\n' >> ~/.nanorc  # โœ…

โŒ Don’t Do This:

# Don't edit sudoers directly
sudo nano /etc/sudoers   # syntax error can lock you out    # โš ๏ธ

# Don't open binary files
nano /bin/ls             # garbage on screen                 # โš ๏ธ

# Don't rely on nano for bulk edits
# That is sed's job                                          # โš ๏ธ

# Don't exit with N when you meant to save
# Ctrl+X then N discards everything                          # โš ๏ธ

# Don't edit a file you haven't backed up
# on a production system without a copy                      # โš ๏ธ

Common Pitfalls

PitfallProblemSolution
Ctrl+X then NDiscards intended changesUse Y to save, or Ctrl+C to cancel exit
Searching loses placeCtrl+W from current positionAlt+\ to go to top first, or repeat with Alt+W
Single cut bufferSecond cut overwrites firstPaste before cutting again
Ctrl+_ doesn’t workTerminal/keyboard mappingTry Ctrl+Shift+Minus, or use Ctrl+W on a known string
Tabs vs spaces confusionYAML/Python breakset autoindent, set tabsize 4
Editing sudoers directlyLockout on typoAlways use visudo
No backup before system editHard to revertcp file file.bak first
Accidentally creating new fileWrong path opens empty bufferCheck title bar filename

Real-World Examples

1. Fix a hostname entry

sudo nano /etc/hosts
# Edit the line, Ctrl+O, Enter, Ctrl+X

2. Change an SSH port

sudo nano /etc/ssh/sshd_config
# Change Port 22 to Port 2222
# Ctrl+O, Enter, Ctrl+X
# sudo systemctl restart ssh

3. Edit a user’s crontab

crontab -e
# If nano is the configured editor, it opens directly

4. Open a config at a known line

nano +128 /etc/nginx/nginx.conf

5. Inspect a sensitive file read-only

sudo nano -v /etc/shadow

6. Save a copy without leaving the editor

nano /etc/fstab
# Edit, then Ctrl+O, change filename to /etc/fstab.new

7. Enable highlighting once

echo 'include "/usr/share/nano/*.nanorc"' >> ~/.nanorc

8. Search a large file quickly

nano /var/log/syslog
# Ctrl+W, type "error", Enter, Alt+W to repeat

9. Edit a Dockerfile on a minimal image

docker run -it alpine sh
apk add nano
nano Dockerfile

10. Recover from an accidental exit prompt

nano important.conf
# Make edits
# Ctrl+X by mistake
# Press Ctrl+C to cancel and continue editing

Visual: The nano screen

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  GNU nano 7.2            /etc/hosts                    โ”‚
โ”‚                                                        โ”‚
โ”‚  127.0.0.1    localhost                                โ”‚
โ”‚  127.0.1.1    myhost                                   โ”‚
โ”‚  ::1          localhost ip6-localhost ip6-loopback     โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚  ^G Help      ^O Write Out  ^W Where Is  ^K Cut        โ”‚
โ”‚  ^X Exit      ^R Read File  ^\ Replace   ^U Paste      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The exit prompt

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  GNU nano 7.2 *          /etc/hosts                    โ”‚
โ”‚                        โ†‘                               โ”‚
โ”‚                   asterisk = unsaved                   โ”‚
โ”‚                                                        โ”‚
โ”‚  127.0.0.1    localhost                                โ”‚
โ”‚  127.0.1.1    myhost                                   โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚                                                        โ”‚
โ”‚  Save modified buffer?                                 โ”‚
โ”‚   Y Yes                                                โ”‚
โ”‚   N No                                                 โ”‚
โ”‚  ^C Cancel                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The editing loop

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                              โ”‚
โ”‚   nano file                                  โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                โ”‚
โ”‚   โ”‚  Edit   โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜               โ”‚                โ”‚
โ”‚        โ”‚                    โ”‚                โ”‚
โ”‚        โ–ผ                    โ”‚                โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚                โ”‚
โ”‚   โ”‚ Ctrl+O  โ”‚ save          โ”‚                โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜               โ”‚                โ”‚
โ”‚        โ”‚                    โ”‚                โ”‚
โ”‚        โ–ผ                    โ”‚                โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚                โ”‚
โ”‚   โ”‚ Ctrl+X  โ”‚ exit          โ”‚                โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜               โ”‚                โ”‚
โ”‚        โ”‚                    โ”‚                โ”‚
โ”‚        โ”œโ”€โ”€ saved? โ”€โ”€ no โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ”‚        โ”‚                                     โ”‚
โ”‚        โ–ผ                                     โ”‚
โ”‚    prompt returns                            โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: cut, paste, and the single buffer

Buffer before:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ alpha                     โ”‚
โ”‚ beta                      โ”‚
โ”‚ gamma                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Ctrl+K on "alpha":
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ beta                      โ”‚
โ”‚ gamma                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        cut buffer: "alpha"

Move down, Ctrl+U:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ beta                      โ”‚
โ”‚ gamma                     โ”‚
โ”‚ alpha                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        cut buffer: "alpha"

A second Ctrl+K overwrites the buffer:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ beta                      โ”‚
โ”‚                           โ”‚
โ”‚ alpha                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        cut buffer: "gamma"
        (the earlier "alpha" is gone from the buffer)

Visual: choosing the right editor

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  What kind of edit?                                   โ”‚
โ”‚                                                       โ”‚
โ”‚  One or two lines in one file, right now              โ”‚
โ”‚      โ””โ”€โ”€โ–บ nano                                        โ”‚
โ”‚                                                       โ”‚
โ”‚  Sustained code or config work, on a remote server    โ”‚
โ”‚      โ””โ”€โ”€โ–บ vim                                         โ”‚
โ”‚                                                       โ”‚
โ”‚  Same replacement across a file or many files         โ”‚
โ”‚      โ””โ”€โ”€โ–บ sed                                         โ”‚
โ”‚                                                       โ”‚
โ”‚  A file with its own mandatory editor                 โ”‚
โ”‚      โ””โ”€โ”€โ–บ visudo, crontab -e, systemctl edit          โ”‚
โ”‚                                                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
SaveCtrl+O, Enter
ExitCtrl+X
Cancel exitCtrl+C at prompt
SearchCtrl+W, Alt+W
Cut / pasteCtrl+K / Ctrl+U
Go to lineCtrl+_
Open at line Nnano +N file
Read-onlynano -v file
Config file~/.nanorc
Best useQuick, human-scale edits

Key takeaways:

  • nano is modeless and self-documenting โ€” the shortcut bar is always visible, so nothing has to be memorized before starting
  • Ctrl+O saves, Ctrl+X exits, Ctrl+C cancels an exit โ€” those three cover the whole interaction loop
  • Search with Ctrl+W and repeat with Alt+W โ€” searching beats scrolling in every file longer than a screen
  • Ctrl+K cuts, Ctrl+U pastes, and there is one buffer โ€” the buffer holds only the most recent cut
  • nano +N file opens at line N and nano -v file opens read-only โ€” both are habits worth forming for system files
  • ~/.nanorc with line numbers and syntax highlighting turns nano from spartan into comfortable with two lines
  • nano is not the right tool for bulk replacements or serious code work โ€” that is sed and vim respectively, and knowing the boundary is part of knowing the tool
  • nano is the editor most likely to be present when a system is broken, which is reason enough to know it well

Remember: nano is not a compromise or a beginner’s toy โ€” it is a deliberately simple editor that solves the most common real-world editing task: one person, one file, one small change, right now. Its visible controls and modeless operation remove the two barriers that make terminal editing intimidating. Learn the five keystrokes that matter, configure line numbers and highlighting, and nano becomes a reliable tool you can reach for on any system, including the ones that are barely running.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!