Nano, when compared to other popular Command Line Editors like Vim or Emacs, is a slim editor which can be used with Syntax highlighting as well. Still, for many beginners it is not very obvious how to work with the editor. For instance it is not obvious how to save and exit Nano as you can not use your mouse to point and click. Let's explore the editor and the commands to save and exit Nano together.
Alright, first things first. We can launch nano by just typing `nano` in the console. This would open an editor which is not related to any file. To open a (text)file - some code or notes - we can call nano with the corresponding filepath of the file:
As soon as the editor is opened, you can start writing right away. This is different to an editor like vim, where you need to launch a command to be able to enter some characters.
Let's add some content:
In the top right corner Nano will tell you that the current state of the content is "Modified", hence unsaved. Furthermore, for well known languages Nano will highlight the code.
So far we have managed to open a file and add some content, great! But how can we save this content to the opened file? This is usually achieved by the Command "CTRL+O".
By triggering this command Nano will ask you to which file name you would like to save the content. In our case, we opened a file, so Nano will suggest the same filename. By confirming with Enter, Nano will overwrite the opened file contents with the content we modified. Furthermore we will see the number of lines that has been written to the file in the bottom information field of Nano.
Finally, to finish our work on a file, we need to close Nano. This can be achieved by the command "CTRL+x", which stands for Exit. When the file is saved, Nano will close. But, when Nano is in the "modified" mode, as we have seen before, it will ask you if you would like to save the content.
By confirming with "Y" Nano will execute the save operation as we have seen before. With this knowledge, we can save us a bit of work. We don't need to trigger the save command explicitly. We could have as well just open the file, modify the content and hit the exit command. In the end, the result is the same.
Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.