nano is a Command Line Interface text editor for GNU/Linux designed to emulate Pico text editor. It is the standard de facto text editor of Linux for system maintainers, comes pre-installed on Ubuntu and its derivative including Linux Mint. It’s fairly advanced for newbies but not too hard to get accustomed to. Well, there is a saying that everything has a learning curve.
nano is for everyone
Anyone, even enthusiast too! But it’s best if you are constantly on the terminal or edits text files regularly. nano is awesome for programmers!
Okay, let’s roll! Here’s a shortcut to opening your terminal and launching nano. Press ctrl+alt+t and type in nano you’ll get a window such as shown below -
Pros and cons
Fortunately, there is only one pro and a con. The pro is that it’s powerful and easier (than vi), the con “keyboard shortcuts” is totally different to traditional text editors.
A very good idea to practice right now is creating a txt file and make some notes in it. So here we go. A note taking file about what to do today.
Creating the file
Typing and saving
Let’s type in something like this:
8 AM- Lunch
1 PM- Tea
5 PM- Dinner
To save the above text file press ctrl+o then Enter key and you’re done.
All done well and now we might just exit and make the day here. Press ctrl+x and your program exits.
If you wish to open the file again and edit it, maybe because you want to take note of something more important than the timetable. Reopening the file is same as creating the file and then here are some of the things you’ll be carrying out now:
Moving up and down
Press ctrl+n to move down
Press ctrl+p to move up
Hard to consume that shortcut? Take ‘n’ as in next and ‘p’ as previous. Tada! And so on for the remaining down there and use your own acronym too. It helps!
Letter and word traversing
To move your cursor one word at a time press ctrl+space and the reverse of moving back one word at a time is esc+space.
For individual letters; ctrl+f as in forward and ctrl+b in reverse
Well, then what about the end and beginning of the current line? Much needed because you might want to edit the last line first or vice versa. Press -
ctrl+e to bring your cursor to the end of the current line and ctrl+a to the beginning of the current line.
Copy and paste
To select the text; position your cursor (let’s say) at 1 PM, press esc+shift+a and you’ll notice the status below has changed from [Read 3 lines] to [Mark Set], start selecting till the end of the line.
Done? Then press esc+6 to copy the text. Position your cursor to last line and press ctrl+u and it’s posted as shown below.
And in case you wish to undo the selection thing press the same key combination you did to select text before i.e. esc+shift+a.
Cut and paste
To cut text do over the “select” thing on the last line and press ctrl+k and your text disappear. This cut tool can also be used to delete lines you don’t need at all.
Pasting as you might’ve guessed is the same as taught above.
You might have noticed this below status: “^W Where is”. If you’ve guessed it correctly it’s the find tool. Go on enabling it and search for some word say “Tea”.
And in case you wish to escape from finding utility all you’ve to do is press ctrl+c and it’ll be canceled.
Find and replace
This is a very handy tool if you need to find and replace words simultaneously. To find words press esc+r and you’ll get a dialog at the bottom.
Type in “Lunch” and press Enter key then type in the replacement text as “Morning food”. nano will ask you if you wish to replace that instant of the word Lunch being found.
Press y and the word gets replaced.
Maybe you want a clean interface as you start up nano? Pass in -x as an additional argument. So for the above note taking file, you’d do it this way to get the output as below.
nano -x note.txt
Then again for the fairly advanced users, you might want to enable suspension of nano for later purpose. Here’s the argument to enable it -
nano -x -z note.txt
It’s also true that nano enables suspension by default but not just on all distributions (like Slackware). You have to explicitly pass the argument to enable it before nano complains.
Well, that’s it. A lengthy tutorial worth learning. Again some might yammer it’s unnecessarily difficult for some shortcut keys above and better left with those arrow keys on the keyboard and pre-defined “home” “end”, etc… Oh no, NO objection to that. But the fact is there’s no guarantee everyone has the same keyboard layout and some might not have those pre-defined keys too.
A programmer? System maintainer? Or an Enthusiast? Nano’s out there for you CLI lovers!
Submit your topic