A look at the nano text editor in GNU/Linux - gHacks Tech News

A look at the nano text editor in GNU/Linux

Given that I have been writing the odd article here and there about server work, hosting, VPS and the like, I thought that perhaps an article about editing configuration files / text documents in a command line scenario might be a good idea.

There are a few major text editors out there, some more user-friendly while some are more complex but bring extra power and configuration (I'm looking at you Vim.)

The editor that most users who are new to the world of working with text only will likely start with, is called Nano.

Nano

Nano

Nano comes installed with most modern distributions of GNU/Linux, but you MAY run into the odd one that doesn't. If for some strange reason you do not have it, it's guaranteed to be in the main repositories for your distribution.

Nano, in my opinion is relatively straightforward to use, it has a list of various commands that can be used at the bottom of the screen in a legend for you, there's no mucking about with various 'modes' like with other editors, and it has all the functions needed for the basics.

A quick how-to on Nano

To start, open a terminal window and navigate to any directory you choose, or just use your home directory. Once ready, type: nano

Tip: You can load a file in nano directly when you load the editor by adding its path to the command, e.g. nano thisismyfile. If the file does not exist, it will create a new buffer with that filename instead.

Once the editor is open, take a look at the legend of commands at the bottom of the screen. You'll note that they each have either a ^ or and M beside them; these signify which key needs to be pressed with the corresponding second key (such as ^K to Cut Text.)

The keyboard shortcut keys are:

  • ^ = CTRL
  • M = ALT

A useful command that you may make use of quite a bit in the beginning is Ctrl-G to bring up the help documentation of nano. Another is Ctrl-O to save the text file that is open in the editor at the time.

Text editing

Highlighting text in Nano is done by holding the SHIFT key and then using your arrow keys, such as when you want to highlight a word to cut it. You may also use Ctrl+^ to mark text instead.

Navigating text in Nano is fairly easily done either via Arrow Keys, or by using commands such as CTRL+ArrowKey to navigate forward/backward by WORD rather than by LETTER, or CTRL+ArrowKey to navigate PARAGRAPH up and down.

  • Ctrl-A jumps to the top of a document,
  • Ctrl-E to the end of the document.
  • Ctrl-Y moves up a page.
  • Ctrl-V moves down a page.
  • Alt-^ copies lines (or Alt-6)
  • Ctrl-U pastes text
  • Ctrl-W searches for text

Another useful function especially when dealing with error output from something you are trying to do, is to navigate to a specific line of text.

Let's say that your nginx finds an issue in one of your configuration files for a website you are hosting, and the output tells you that the error is on line 173 of myconfig.conf. What we can do is open the file in nano, and quickly jump to that specific line by pressing ^_ (CTRL+SHIFT+DASH key.) Nano will then prompt you to enter the line, and column numbers. Simply enter "173" and voila, you are now at your problem!

Nano Helpscreen

There are many other possible ways to use Nano, it has many commands, not all of which are listed at the bottom of the screen; to access them, press CNTRL+G to bring up (or hide) the help screen.

The final thing in this quick tutorial, is how to exit and save a document in Nano.

CTRL+X is your hotkey for 'exit'. If you have NOT edited a document, Nano will simply quit. However, if you have made any changes, nano will then ask you "Save Modified Buffer?" which is asking if you want to save. You can press Y or N for yes or no. Pressing N will simply exit without saving changes, where pressing Y will then ask you what you want to name the file. You can keep the same name simply by pressing ENTER, or you can enter in a new name.

That's it! These are the absolute basics of using the Nano text editor.

Here are some resource pages that you may find useful:

What about you? Do you use another editor? If so, why?

Summary
A look at the nano text editor in GNU/Linux
Article Name
A look at the nano text editor in GNU/Linux
Description
Mike's beginner tutorial on using the nano text editor on GNU/Linux machines walks you through the basics so that you can get started editing right away and without frustration.
Author
Publisher
Ghacks Technology News
Logo
Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. HK-Rapper said on July 22, 2017 at 10:14 am
    Reply

    CTRL+6 to set a start point for selection of text is great too

    nano is just more comfy than vim

  2. Mark Hazard said on July 22, 2017 at 2:22 pm
    Reply

    I use Leafpad because it has a menu system and I don’t have to use keyboard shortcuts.

  3. Maou said on July 22, 2017 at 3:27 pm
    Reply

    My router and all of my computers runs Nano, I don’t really need Vim “power”, Nano is good enough for me.
    I like to enable line numbers (nano -l)

  4. pd said on July 22, 2017 at 5:52 pm
    Reply

    Nano is a lifesaver. Not because it’s a great program, just because it’s not a horribly arcane program like most other text editors commonly installed on Linux.

    If only they could change thier strange mapping of Ctrl + S which usually results in some sort of concession to possible criticism (?) : “XOFF ignored, mumble mumble” instead of writing Out the file and eXiting it in one shot, rather than having to to Ctrl + O, then Ctrl + X for that task.

  5. Lumpy Gravy said on July 22, 2017 at 9:37 pm
    Reply

    In case anyone here is interested in more applications for the Linux console, there’s K.Mandla’s Inconsolation blog …

    http://inconsolation.wordpress.com/

    He (she?) has tried out and commented on hundreds of them. Unfortunately the articles are indexed alphabetically by program name, so it’s impossible to browse through them by function. Still, I find this site very interesting and useful.

  6. Sean said on July 23, 2017 at 1:13 am
    Reply

    nano is a good turnkey editor, but if you find yourself actually reading the help page, you should bite the bullet and learn VI. Its key combos are dramatically less arthritis inducing (Ctrl+Shift+- to jump…really?), and it’s available in the base install of Solaris and BSD derivatives as well as GNU environments.

    Please don’t confuse VI with VIM either. VIM is much larger and includes a lot of usability cheats which enable novices to use it like a broken version of Notepad. Learn the basic movement commands, then search up “Your problem with Vim is that you don’t grok vi.” on Stack Exchange. If you’re on the command line and not using marks or registers regularly, you’re almost certainly doing it wrong.

  7. Anonymous said on July 23, 2017 at 10:30 am
    Reply

    “What about you? Do you use another editor? If so, why?”

    To paraphrase a comment I ran across some late night in a forum topic long long ago…

    “Windows with all its point an clicks presumes people are stupid while Linux on the other hand makes you prove it”

    An now that I have created a context for my answer I will just say…Im happy with who I am and prefer to use a simpler PnC approach like leafpad, Gedit or even Kate.

    1. Anonymous said on July 23, 2017 at 6:17 pm
      Reply

      Nobody uses nano as their primary editor. The premise of the article is that PnC isn’t simple in a lot of remote environments.

  8. mikef90000 said on July 24, 2017 at 1:19 am
    Reply

    Nano is a fine editor for quick admin tasks and is usable over SSH.
    If you have some heavy bulk editing tasks try the Hessling editor (package name ‘the’), a clone of the mainframe editor Xedit. No fussy modes to deal with ….

  9. pespacova said on July 25, 2017 at 1:56 pm
    Reply

    Nano is a great simple editor that gets the job done and is available as default in most distros. Nano is my goto editor for 95% of my editing tasks in Linux..

    In contrast, to briefly touch on the Windows notepad application which is default, that still in 2017 and after many Windows 10 iterations, still doesn’t support UTF-8 (lets just leave it at that), thankfully there are options available, but the point is obvious.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.