Nano: The Simple Text Editor Every Terminal User Should Know
Nano is a terminal-based text editor that is straightforward, easy to learn, and widely available across most Linux distributions. Whether you need to make quick edits to a text file or you're working on a system without a graphical user interface (GUI), Nano is your go-to tool. While some might argue that you should invest time in learning Vim, I believe that it's not always necessary to spend so much time mastering Vim, especially when most of your text editing will likely be done using a GUI-based editor. However, knowing the basics of Vim can be advantageous since it offers features exclusive to Vim, and some minimalistic distributions come pre-installed with only Vim.
But if your goal is to cover the majority of your text-editing needs quickly and efficiently, mastering Nano is the way to go. Here are some essential Nano commands that will help you handle 99% of text editing tasks:
1. Opening Files
nano test.txt
: Opens the file normally. Sometimes, you might need to addsudo
in front of the command to edit system files.nano -v test.txt
: Opens the file in view-only mode, preventing any accidental edits.
2. Saving and Exiting
Ctrl + o
(Write Out): Prompts you to confirm the file name before saving the changes.Ctrl + x
: Exits Nano. If there are unsaved changes, Nano will ask whether you want to save them.Ctrl + s
: Saves any unsaved changes instantly.
3. Copy, Cut, Paste, and Delete Text
Alt + a
: Begins text selection, marking the cursor's current position.Ctrl + Alt + 6
performs the same action.Ctrl + k
: Cuts the entire line where the cursor is located. You can use it repeatedly to cut multiple lines.Ctrl + u
: Pastes the last cut text at the current cursor position.Alt + r
: Replaces a specific text with another.Ctrl + d
: Deletes the character at the cursor's current position.
4. Searching for Text
Ctrl + w
: Initiates a search within the document. After pressing this, type the text you want to find and press Enter.Alt + w
: Moves to the next occurrence of the searched text.Alt + q
: Moves to the previous occurrence.
5. Navigating the File
Alt + /
: Moves the cursor to the end of the file.Alt + \
: Moves the cursor to the beginning of the file.Alt + g
: Prompts for a line and column number to jump to that specific location in the file.Ctrl + y
: Scrolls up one page.Ctrl + v
: Scrolls down one page.
6. Undo and Redo
Alt + u
: Undoes the last action.Alt + e
: Redoes the last undone action.
7. Miscellaneous Commands
Ctrl + t
: Executes a command within the Nano editor.Alt + x
: Disables help mode.Alt + p
: Toggles the visibility of whitespace characters on or off.Ctrl + r
: Reads and inserts another file into the current file.
Mastering these commands will ensure that you're well-equipped to handle almost any text editing task in the terminal. While Vim has its place and power, Nano provides a more straightforward and accessible solution for most users. So next time you need to edit a file, give Nano a try—you might find it to be the perfect tool for your needs.
If you are interested to learn all the nano commands, visit this this link.
Subscribe to my newsletter
Read articles from Md Sakib Sadman Badhon directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Md Sakib Sadman Badhon
Md Sakib Sadman Badhon
Hello, I am Badhon. I tend to forget things easily which is why I opened this blog.