Comprehensive Guide to Nano Text Editor with Key Commands


Nano is a user-friendly and lightweight command-line text editor. It's an excellent choice for editing files directly in the terminal, especially for users new to the command line. In this tutorial, we will explore the basic usage of Nano, including a detailed breakdown of essential commands for efficient text editing.
Getting Started with Nano
To open Nano, type the following command in your terminal:
nano filename
If the specified file doesn't exist, Nano will create it.
You'll see a blank interface or the contents of the file if it already exists.
Nano Interface Overview
When you open Nano, you’ll notice:
Editing Area: The main screen where you can type or modify text.
Command Bar: At the bottom, Nano displays key commands for navigation and file operations.
Status Line: Shows messages like file name, search results, or errors.
Essential Nano Commands
Here’s a list of frequently used commands in Nano, explained with examples:
1. Navigating the Text
CTRL + A
: Jump to the beginning of the current line.CTRL + E
: Jump to the end of the current line.CTRL + Y
: Scroll one page up.CTRL + V
: Scroll one page down.
2. Getting Help
CTRL + G
: Opens the Help window with a list of all available commands.
Example: If you’re unsure of a command, press
CTRL + G
for an interactive reference.
3. Saving Files
CTRL + O
: Save the current file.Nano will prompt you to confirm or modify the file name.
Press
Enter
to save.
Example:
Edit your file.
Press
CTRL + O
to save changes.Confirm the file name by pressing
Enter
.
4. Searching and Replacing
CTRL + W
: Search for a specific word or phrase.- Use
ALT + W
to find the next occurrence of the same phrase.
- Use
CTRL + \
: Replace a word or a regular expression.- Nano will prompt you for the search term and the replacement text.
Example:
To replace all occurrences of “foo” with “bar”:
Press
CTRL + \
.Enter "foo" as the search term.
Enter "bar" as the replacement term.
5. Cutting, Pasting, and Selecting Text
CTRL + K
: Cuts the entire line where the cursor is located.CTRL + U
: Pastes the cut text at the current cursor position.ALT + A
: Enables text selection mode.- Combine with
CTRL + K
to cut selected text.
- Combine with
Example:
Place the cursor at the start of a block.
Press
ALT + A
and navigate to select text.Use
CTRL + K
to cut it andCTRL + U
to paste elsewhere.
6. Formatting and Justification
CTRL + J
: Justifies (aligns) the current paragraph.
Example: If a paragraph looks misaligned, place the cursor within the paragraph and press
CTRL + J
to adjust it.
7. Cursor and Line Information
CTRL + C
: Displays the current cursor position (line, column, and character).CTRL + _
: Moves the cursor to a specified line and column number.
Example:
Press
CTRL + _
.Enter
10,5
to move to line 10, column 5.
8. Opening and Inserting Files
CTRL + R
: Opens another file and inserts its content into the current file at the cursor position.
Example: To merge content from
file2.txt
into your current file:
- Press
CTRL + R
, then typefile2.txt
and hitEnter
.
9. Spell Checking
CTRL + T
: Invokes the spell checker if it is available.
Ensure you have a spell checker installed (e.g.,
aspell
orhunspell
) for this feature to work.
10. Exiting Nano
CTRL + X
: Exits Nano.- If there are unsaved changes, Nano will prompt you to save before exiting.
Sample Workflow Using Nano
Let’s edit a file step by step:
Open a file:
nano example.txt
Navigate and edit the text:
Use
CTRL + A
orCTRL + E
to jump to the start or end of a line.Use
CTRL + W
to search for a word.
Save your changes:
- Press
CTRL + O
and confirm the file name by pressingEnter
.
- Press
Cut and paste lines:
- Place the cursor on a line, press
CTRL + K
to cut, andCTRL + U
to paste it elsewhere.
- Place the cursor on a line, press
Exit Nano:
- Press
CTRL + X
.
- Press
Conclusion
Nano is an intuitive text editor for terminal-based editing. With these commands, you can efficiently navigate, modify, and manage text files. While it’s simple to use, mastering these shortcuts will significantly enhance your productivity.
Start practicing these commands and make Nano your go-to editor for quick text file edits!
Subscribe to my newsletter
Read articles from Junaid Bin Jaman directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Junaid Bin Jaman
Junaid Bin Jaman
Hello! I'm a software developer with over 6 years of experience, specializing in React and WordPress plugin development. My passion lies in crafting seamless, user-friendly web applications that not only meet but exceed client expectations. I thrive on solving complex problems and am always eager to embrace new challenges. Whether it's building robust WordPress plugins or dynamic React applications, I bring a blend of creativity and technical expertise to every project.