Learn how to use the beginner-friendly Nano text editor by learning the most essential commands for beginners.
There are many text editors on the market. Their difficulty ranges from beginner-friendly to advanced. Nano is largely considered to be in the beginner-friendly category while the Vim editor is in the advanced category.
Although Nano is considered “easy for beginners” (relatively) it can take some to get used to it. In the beginning, Nano can be intimidating, especially if you’re using it to configure servers, like a VPS. That’s why you start learning Nano in a low-risk environment before you start applying your skills in the wild.
The following small handful of commands will take away the intimidation factor of using Nano once you’ve practiced them a few times. They will become your go-to escape commands if you should run into trouble.
Let’s learn how to do the following in the Nano editor:
- Open a file in Nano
- Make changes to the file
- Save the changes
- Discard changes
- Exit Nano
Start by opening your terminal. If you’re using Linux or Mac, you should already have the Nano editor installed. On Windows, you might have to download it from the official website.
First, create a file via your terminal:
Now open it in Nano:
That’s it, you’re now inside the Nano editor. Or in other words, you just opened your newly created file
learning_nano inside Nano!
As you can see the file is empty. Try typing some text, anything you want.
- To navigate around, use your keyboard’s arrow keys.
- Deleting text works the same as anywhere else, just hit the Delete key (Backspace) on your keyboard.
- You can also copy-paste some text in here (Cmd + V on Mac, or Ctrl + V on Windows), which you’ll often do in real-life.
You’ll notice that in the top right corner, it now says “Modified”:
Great, it’s time to save your file and exit Nano.
While inside Nano, press Ctrl + X.
Now Nano asks if you want to save your file before you exit:
- If you press Y you save the file.
- If you press N you don’t save it, and Nano immediately closes.
Try pressing N first.
Now Nano is closed and you’re back in your regular terminal shell.
Open Nano again:
Your file is empty, as it should be because you chose to not save the text you typed before, by hitting N.
Type some text inside your file again, and press Ctrl + X just like before.
Then press Y to save it.
Now you’ll be asked for a file name. This is if you want to save your file as a new file. If you don’t, just hit Enter (right after pressing Y). Nano will close, and your file changes are saved.
To confirm that Nano indeed saved your changes, open your file again:
If you don’t modify your file right after opening it, you can exit Nano immediately by pressing Ctrl + X. Try it.
You have just learned the most essential commands of using Nano on your local machine, and you now know enough to edit any file with Nano without much risk.
There’s much more to learn in Nano, however, many of you won’t need to learn much more than this to use Nano in real-life, which is why I’m ending this tutorial now. Often when you’re using Nano it will be in a context where you have to do something simple, like open a server file and add/modify/remove something like a password or a protocol, which you can copy-paste in Nano just like anywhere else.
Remember, if you’re following a tutorial in the backend/server-side category and you think you’ve done something wrong, you can always exit Nano (Ctrl + X and press N) to discard your changes. That’s your get out of jail card.
Exiting without saving file changes (if you’re worried) in Nano (or any editor) is always better than saving, and then exiting because in some situations saving a faulty file can cause your server to stop working, which could bring down your website or other services temporarily.