A Beginner's Guide to Nano Text Editor on Ubuntu
Nano is one of the most user-friendly and widely available text editors in the Linux world, especially for beginners. Whether you’re editing configuration files or writing scripts, Nano is a great tool to use in the terminal. In this guide, we’ll walk through how to install, open, and use Nano effectively on Ubuntu.
Why Use Nano?
Nano is ideal for beginners because:
- It’s simple and easy to use.
- It’s available on most Linux distributions by default.
- It displays helpful shortcuts at the bottom of the editor.
Unlike more advanced editors like Vim or Emacs, Nano doesn’t require any prior knowledge of modes or complex commands—just simple keyboard shortcuts to edit and save files.
How to Install Nano on Ubuntu
In most cases, Nano comes pre-installed on Ubuntu. However, if for some reason it’s not installed, you can easily install it with the following command:
sudo apt update
sudo apt install nano
Once installed, you can verify it by running:
nano --version
Opening a File with Nano
To open an existing file or create a new one, use the following command:
nano filename
- If filename exists, it will open that file.
- If it doesn’t exist, Nano will open a blank file with that name, and you can start editing.
For example:
nano textfile.txt
Nano Basic Editing Commands
When you open Nano, you’ll notice a few things:
- The main part of the screen is the file you are editing.
- At the bottom of the screen, you’ll see a list of shortcuts (e.g.,
^X
meansCtrl + X
).
Here are some basic commands you’ll use frequently in Nano:
Command | Action |
---|---|
Ctrl + O | Write (save) the file. |
Ctrl + X | Exit Nano. |
Ctrl + K | Cut text (deletes the current line). |
Ctrl + U | Paste the cut text. |
Ctrl + W | Search for text in the file. |
Ctrl + G | Display help screen (this shows other shortcuts). |
Ctrl + C | Show the current cursor position (line and column). |
Saving a File
Once you’ve made changes to the file, you can save them by pressing:
Ctrl + O
Nano will prompt you for confirmation to save the file. Press Enter to confirm.
Exiting Nano
After saving your changes, you can exit Nano by pressing:
Ctrl + X
If you haven’t saved your changes, Nano will ask you if you want to save the file before exiting.
Cutting, Copying, and Pasting Text
- To cut a line, position your cursor on the line and press:
Ctrl + K
- To paste the cut line, move the cursor to the desired location and press:
Ctrl + U
- To copy text, first cut it, then immediately undo the cut using
Ctrl + U
. This will paste the text back and copy it to the clipboard.
Navigating in Nano
Moving the Cursor
- Arrow keys: Move up, down, left, or right.
- Ctrl + A: Move to the beginning of the line.
- Ctrl + E: Move to the end of the line.
- Ctrl + Y: Move up one screen (page).
- Ctrl + V: Move down one screen (page).
Searching for Text
To search for text in the file:
- Press
Ctrl + W
. - Type the search term and press Enter.
- Nano will jump to the first match in the file. Press
Ctrl + W
again to find the next match.
Nano Configuration
Nano has a configuration file located at ~/.nanorc
, where you can customize its behavior. Here are a few common options:
Enable Line Numbers
To display line numbers, add the following line to ~/.nanorc
:
set linenumbers
Enable Syntax Highlighting
Nano supports basic syntax highlighting for various programming languages. This feature is often enabled by default, but you can add or modify it in the config file.
For example, to enable syntax highlighting for Python, add:
include /usr/share/nano/python.nanorc
Conclusion
Nano is a powerful yet simple text editor that’s perfect for beginners who are just getting started with command-line text editing on Linux. While it may not have all the features of more advanced editors, it provides everything you need for basic editing tasks and is widely supported across Linux distributions.
With the basics of opening, editing, and saving files, you’re ready to start working with Nano on Ubuntu. As you become more comfortable with it, you can explore its more advanced features, such as syntax highlighting and multi-file editing.