Nano is a simple, user-friendly text editor for Linux designed for easy use on the command line. It’s excellent for individuals new to command-line editing or those who prefer straightforward use without the difficulty of more advanced editors such as Emacs or Vim. This article will guide you through the basics of using Nano, from opening and editing files to saving your changes.
Installing Nano
Nano typically comes pre-installed with macOS and many Linux distributions. However, if it’s not installed, you can easily add it using your package manager.
For Debian-based systems like Ubuntu, type:
$ sudo apt-get install nano
For Arch-based systems, use:
$ sudo pacman -S nano
For Red Hat–based systems like CentOS, use:
$ sudo yum install nano
Opening and creating files in Nano
To open a file in Nano, use the command:
$ nano filename
Once entered, a new editor window will pop up that will allow you to edit the file. There is a list of basic command shortcuts to use with the nano editor at the bottom of the window.
To get a list of all commands, type Ctrl+g
If the file does not exist, Nano will create it for you once you save your changes.
Basic navigation and editing
Once inside Nano, you will see a basic interface with a status bar at the bottom displaying helpful shortcuts.
Moving Around
- Arrow Keys: Move the cursor up, down, left, and right.
- Page Up/Page Down: Quickly navigate through longer documents.
Editing Text
- Typing: Type normally to insert text at the cursor’s position.
- Backspace/Delete: Use to remove characters.
Copying, Cutting, and Pasting
To select text, place the cursor at the start of the section and press Alt+A to set a mark. Then, use the arrow keys to highlight the text by moving the cursor to the desired endpoint. To cancel the selection, press Ctrl+6.
To copy the highlighted text, press Alt+6, or use Ctrl+K to cut it.
To cut entire lines, position the cursor on the line and press Ctrl+K. You can cut multiple lines by repeating this command.
To paste the text, move the cursor to the desired location and press Ctrl+U.
Common Shortcuts
Nano uses the Control (^) key to trigger commands. Here are some essential shortcuts:
- ^O (Ctrl+O): Save the current file. Nano will prompt you to confirm the filename.
- ^X (Ctrl+X): Exit Nano. If there are unsaved changes, you’ll be prompted to save them.
- ^K (Ctrl+K): Cut the entire line where the cursor is located.
- ^U (Ctrl+U): Paste the last cut text at the cursor position.
- ^W (Ctrl+W): Search for a string of text within the file.
- ^C (Ctrl+C): Show the current cursor position in the file (line and column number).
Saving Your Work
Once changes are added, save the file using:
- ^O (Ctrl+O): This opens a prompt at the bottom. Press Enter to confirm the filename or edit it if needed.
- Once confirmed you will see “Wrote X lines” at the bottom, indicating the save was successful.
Exiting Nano
To exit Nano, use:
- ^X (Ctrl+X): If there are unsaved changes, Nano will ask if you want to save them. Press Y to save, N to discard, or Ctrl+C to cancel and return to editing
Additional features
Nano includes some additional functionality that can be helpful:
Searching and Replacing
- ^W (Ctrl+W): Search for text. After entering the search term, press Enter to find the next occurrence.
- ^\ (Ctrl+ ): Find and replace text. Nano will prompt you for the search term, then the replacement text, allowing you to replace all instances found.
Undo and Redo
- M-U (Alt+U): Undo the last action.
- M-E (Alt+E): Redo the last undone action.
Line Numbers
To display line numbers, you can start Nano with the -l flag:
$ nano -l filename
Or, enable line numbers within Nano by pressing Alt+Shift+#.
Customizing Nano
Nano can be customized by editing the .nanorc file in your home directory. You can enable features such as:
- Line Numbers: Add set line numbers to show line numbers by default.
- Syntax Highlighting: Include “/usr/share/nano/*.nanorc” to enable syntax highlighting for various file types.
- Auto Indent: Add set auto-indent for automatic indentation when creating new lines.
Simple Nano usage
Here is a simplified guide on how to use Nano:
- Type nano followed by the filename on the command prompt
- Edit the file to your liking
- Save and exit by using Ctrl-x
Conclusion
Nano is a great starting point for a beginner or anyone who needs a quick, straightforward text editor on the command line. With its basic interface and simple shortcuts, Nano makes text editing in the terminal accessible to everyone. Experiment with the commands, customize your settings, and you’ll soon be easily navigating and editing files.

