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.

Using Software

15 Comments

  1. 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.

  2. 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.

  3. Nordin

    Oh thank you for explaining nano Editor,
    never knew it has such features. always use it to past codes using a mouse :).

  4. z

    scroll paste or thirdbutton paste with mouse works too..

    • 3rd buttons paste works everywhere in terminal, so, yes it works on nano too. Thanks fot take the time to read and comment!

  5. DonPedro

    The one that I use. It’s simple and makes the job done.

  6. 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

  7. 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.

  8. Richard

    Thanks for the useful article! Just a small correction: the shortcut for search/replace is ^.

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions

%d bloggers like this: