Nano is a popular command-line text editor known for its simplicity and ease of use. Till now we have seen some very basic commands and terminologies. So now it’s time for you to grow up and start editing FILES !! In this article, we’ll cover everything from basic editing to advanced features like opening multiple files, searching, replacing, and much more.
What is Nano Text Editor?
Nano is a terminal-based text editor designed for Unix-like operating systems such as Linux and macOS. It comes pre-installed on most Linux distributions, making it accessible to almost every Linux user.
Benefits of Using Nano
- Simple Interface: Beginner-friendly, with visible commands at the bottom of the screen.
- No Learning Curve: Easier to learn compared to more complex editors like Vim or Emacs.
- Lightweight and Fast: Works efficiently on even the most basic systems.
Popular Alternatives to Nano
- Vim: Powerful but has a steep learning curve.
- Emacs: Highly customizable but resource-heavy.
- VSCode & Sublime Text: GUI-based editors for developers.
Understanding Nano’s Symbols: ^
and M
When you open Nano, you’ll notice symbols like ^
and M
displayed at the bottom, indicating shortcut keys.
^
(Caret): Refers to the Ctrl key. Example:^X
means Ctrl + X.M
(Meta): Refers to the Alt key. Example:M-U
means Alt + U.
Tip: If the
Alt
key doesn’t work, try pressing theEsc
key instead, followed by the corresponding letter.
Now that you know about the symbols we can finally get into editing and see how to work with Nano to edit files 😂. We will go one by one, starting from easy stuff and then moving on to some advance, interesting features that I personally love to use 😅.
1. Basic Editing: Cut, Copy, and Paste
We all copy code from the internet to use in our projects 😆. Therefore, it’s important to start with the same LOL !! I know the cut, copy past in the nano is not that great but it is what it is 🙂.
Cut Text
- Select Text: Use
Ctrl + 6
or holdShift + Arrow keys
to highlight text. - Cut Text: Press
Ctrl + K
( cuts the selected line or text ).
Copy Text
- Select Text: Use
Ctrl + 6
or hold theShift + Arrow keys
to highlight text. - Copy Text: Press
Alt + 6
( copies the selected text ).
Paste Text
- Paste: Move the cursor to the desired location and press
Ctrl + U
. (Ctrl + V
also works ☺️ )
2. Searching, Replacing, and Navigating
There are so many words in a file and we can’t just search manually for something across the ocean of words. So, let’s see how to search, replace and navigate in Nano.
Search for Text
- Press
Ctrl + W
, enter the search term, and press Enter.
Go to a Specific Line or Column
- Press
Ctrl + /
( forward slash ), enter the line and column number, and press Enter. ( You can just write the line number to go to a specific line )
Replace Text
- Press
Ctrl + .
- Enter the search term, press Enter, then enter the replacement text.
- Press A to replace all occurrences or Y/N to confirm each replacement.
3. File Management in Nano
Opening Multiple Files
- Open multiple files by listing them in the command:
nano file1.txt file2.txt
Switching Between Files
- Press
Ctrl + X
to close the current file (if saved). - Use
Alt + >
to switch to the next file. - Use
Alt + <
to switch to the previous file.
4. Running Commands from Nano
You can execute system commands directly from Nano without leaving the editor.
Execute a Command
- Press
Ctrl + T
to open a command prompt inside Nano. - Type the command and press Enter.
For example:
ls -l
5. Browsing Files from Nano
Nano also includes a file browser for easier file management. This means you can navigate through directories just like in a file explorer and select which file you want to select. You don’t have to write a whole path of the file, visually go to the file and hit Enter.
Open File Browser
- Press
Ctrl + R
andCtrl + T
to launch the file browser. (Ctrl + R
is for reading a file you can also write to a file usingCtrl + W
) - Use arrow keys to navigate and Enter to open a file.
Conclusion
Nano is good but wait for the next part in which we will see about Vim. I guess, I have pretty much cover most of the things related to nano but there is always something to learn !! So, start messing around with nano.
Pro Tip: Use
Ctrl + G
in Nano at any time to access the built-in help menu with detailed command explanations.