Consider signing up for BitLaunch for use in this exit Nano tutorial.
The Nano text editor was first created by Chris Allegretta in 1999. It was originally named TIP (TIP isn’t Pico). It distributed by the GNU software Foundation and is both freely available and very well supported: https://directory.fsf.org/wiki/GNU
Over the years, Nano has grown to enjoy a devout following. While incredibly powerful, the Nano editor is almost intuitive for the novice and a fantastic addition to any coder or sysadmins’ arsenal. It is a serious competitor for Vi(m) and Emacs power users too. The nano-editor.org website describes Nano as “a small and friendly editor.”
Unfortunately, though, there are still a few things about the editor that confuse beginners, and one of those is how to exit Nano. This tutorial will show you how save and exit Nano, but will also cover some of the basic functions.
Nano Fundamentals
We’ll focus on the commands that will generally be used when first learning Nano. For this tutorial Nano on Mac will be used, but it is available for all platforms.
Once installed correctly simply type nano
in your favorite terminal.
You are taken to a nano instance and presented with 12 basic commands. Some of the commands are listed on the bottom of the screen.
First let’s take a look at the “Get Help” switch by hitting control+G
Scroll down just past the initial help text intro and you get a straight forward intro to the navigation followed by a list of the many options available.
Navigation
Navigation is extremely simple as shown
- Ctrl+Y is for Previous Page
- Ctrl+V is for Next Page
- Ctrl+P is for Previous Line
- Ctrl+N is for Next Line
If you often need a quick reminder of how to do something with a particular tool. You will no doubt find this very helpful. While there are many more options available, these following commands should get you up and running quickly and get your head around the “nano way” of doing things.
Switch | Description |
---|---|
Ctrl+O | Write the current file to disk. |
Ctrl+R | Insert another file into the current one. |
Ctrl+W | Search for a string or a regular expression. |
Ctrl+C | Show current line number and file information. |
Ctrl+J | Justify the current paragraph. |
Ctrl+K | Cut the current line and store it in the cutbuffer (cut). |
Ctrl+U | Uncut from the cutbuffer into the current line (paste). |
Ctrl+T | Invoke the spell checker, if available. |
Ctrl+_ | Go to line and column number. |
Ctrl+_\ | Replace a string or a regular expression. |
How To Exit Nano
Well that is displayed in the default nano buffer as soon as it’s launched, so no secrets there: Ctrl+X. What is awesome though, is the default prompt for the forgetful among us that may not remember to persist to disk when exiting.
As an example: create new file by typing “nano test.abc” at the command prompt. This launches nano with the created file in the current buffer. Enter some text and hit Ctrl+X to exit and get the following prompt:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
Simply enter Y to save your work and exit nano. Alternatively, those wondering how to save and exit Nano can do so b pressing Ctrl + O, followed by Ctrl + X.
That was a brief intro to some of the most regularly used commands in nano. Hopefully it will inspire you to take a closer look at nano. It’s a great text editor that is simple and intuitive.
For some explainers of basic Linux tools, consider our guide to permissions on Linux and on finding files via the command line.