Text console editors are useful in many ways. For example, they’re indispensable for editing files while recovering from a failure. Fedora contains a wide selection of applications for editing text files, ranging from GUI editors like gedit and GNOME Builder to editors that run in the terminal like Vi and Emacs. A terminal based editor — developed under the auspices of the Free Software Foundation — is the GNU nano editor. Nano is a great little tool for getting started with editing files in the Terminal. It has a shallower learning curve than other terminal-based editors — such as Vi — as it displays shortcut for regularly used actions at the bottom of the screen.
GNU Nano
GNU nano was intended to be a replacement of Pico. Pico is a text editor for UNIX, and more specific for the Pine email suite. The original mission of nano: “emulate Pico as closely as possible and then include extra functionality,” although it’s short on extras.
Some of these features are:
- Syntax highlighting
- Mouse support
- Move through pages
- Copying and Pasting
- Deleting Line
- Multibuffer
- Remote edition
Installing nano
GNU nano isn’t in the default installation of Fedora, but it’s in the official repositories. To install use the command:
sudo dnf install nano
Basic operations
The editor works with keyboard shortcuts you can identify at the bottom of the main screen:
To open a file, call it from the terminal with the nano command:
nano fileToOpen
If you don’t specify a file, nano opens an empty file.
In this article, the character ^ means the Ctrl key, and M- stands for Meta. For us in Linux, this usually means the Alt key. You can type normally to start a document, and use arrow keys to move around in it.
One of the most common tasks in an editor is copy and paste. To understand this task in the editor, you need to know that select is called mark, and the clipboard is called the buffer. Knowing this, the steps to copy and paste are:
- Move to the the place you are going to start the copy.
- Start marking the text with ^6
- When you reach the end of the text to copy, press M-6. This moves the marked text to the buffer.
- Move to the destination to paste the text and press ^U.
Cutting is the same process, but the combination after marking the text is ^K. Also notice that if you don’t mark the text, the whole line is sent to the buffer when you use M-6 (copy) or ^K (cut).
Other features
Another feature is the Multibuffer, which lets you open multiple files. Since this is a console utility, there are no tabs to check multiple files. To move between files, use the keyboard shortcuts: M-> or M-. for the next file and M-< or M-, for the previous file.
You can also search text with regular expressions. Use the combination ^W, type the text you’re searching and hit Enter. The cursor moves to the first character when the search pattern is found. To find the next instance, hit M-W.
To search and replace, the combination is ^. The editor prompts you to enter the word for search, and then the word that will replace the searched word. The editor asks you for each instance whether you want to replace:
To close the editor, use ^X at which point you’re asked to save the file. To save a file at any time, use the combination ^O.
There are many other shortcuts. For instance, check out this little list with some of those most used. Also, you can query the official documentation.
Final thought
GNU nano is a minimal editor intended for easy use. Although it may not be ideal for code, remember it was created as an email editor. It’s great for quick edits and to create documents, since it’s minimal and has no GUI — it does everything from your keyboard.
Alfonso Savio
Thank you Eduard for this usefull presentation of GNU nano editor.
Personally I use it since ever for editing system files and bash programming on servers (Vms too), but your post makes me know funcionality I never used.
Eduard Lucena
Thanks to you for taking the time to read and comment!
Rene Reichenbach
I was really happy back in time that there is some useful editor besides vim on the console … 🙂 always use it for git commits as the standard editor or small changes in bash scripts.
Eduard Lucena
Thanks to you for taking the time to read and comment!
Nordin
Oh thank you for explaining nano Editor,
never knew it has such features. always use it to past codes using a mouse :).
Eduard Lucena
Thanks to you to take the time for read and comment!
Eduard Lucena
Thanks to you for take the time to read and comment!
z
scroll paste or thirdbutton paste with mouse works too..
Eduard Lucena
3rd buttons paste works everywhere in terminal, so, yes it works on nano too. Thanks fot take the time to read and comment!
DonPedro
The one that I use. It’s simple and makes the job done.
Eduard Lucena
Thank you for take the time to read and comment!
DonPedro
No biggy. Fedora is excellent distro but the gnome de… Eeeerrr… If you know what I mean. 🙂
David
Can you do something similar on less pager? It’s ridiculously complicated. Trying to do simple things can be complicated. E.g add color, configuration file etc
Thanks
Ryan K
I like Nano. EMacs and Vi uses may scoff, but Pico and Nano happen to be the *nix editors that I learned to use efficiently on the console.
A disadvantage to the key combos however is they tend to not translate at all to other apps, which occasionally leads to the occasional mistake – like using Ctrl-w to save a document but triggers the close-window command.
jpico is also good alternative to nano users as it has all the extra features and customization of the joe editor, but with the key combinations used by pico and nano.
Richard
Thanks for the useful article! Just a small correction: the shortcut for search/replace is ^.