Fedora Magazine: GNU nano: a minimalist console editor

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:

Nano editor Main Screen

Nano editor 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:

  1. Move to the the place you are going to start the copy.
  2. Start marking the text with ^6
  3. When you reach the end of the text to copy, press M-6. This moves the marked text to the buffer.
  4. 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.

Moving through files in nano editor

Moving through files in nano editor

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:

Find and replace in nano editor

Find and replace in nano editor

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.

Source From: fedoraplanet.org.
Original article title: Fedora Magazine: GNU nano: a minimalist console editor.
This full article can be read at: Fedora Magazine: GNU nano: a minimalist console editor.


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *