The Nano Text editor
Shivm Soaini
Math Major Turned AI Enthusiast: Mastering Computer Vision | Building Robust Python Code | Delving Deep into the Math of AI | Sharing Knowledge Through Writing | Ready to Transform Ideas into Reality
Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular command-line editors like vim and emacs.
Nano includes all the basic text editing functionality you would expect: search, spellcheck, syntax highlighting, etc.
To open up a file using nano, run nano FILE. For example, to open up a file "book.txt" using nano, we would run nano book.txt.
nano FILE
We can also use the same command to edit a file that doesn't yet exist (we can then save it and create the file).
To save the file CTRL+O is used.
Suppose we have a file "groceries.txt", we can open and modify it directly from the terminal using nano.
Modify it and save it by pressing CTRL + O and then the Enter key. You can then exit the nano editor using CTRL + X.
Some editors like vim require us to enter "write mode" before we start editing a file, but with nano we can make the changes right away.
We can move the cursor using the arrow keys.
At the very bottom, we'll see a list of shortcuts that we can use inside of nano. These are super useful!
There are tons of shortcuts inside Nano but you'll only need few of them.
You can look at the help page using CTRL+G to know more about the shortcuts.
Searching and Replacing with nano
Use CTRL+W and then enter a search phrase to search FORWARD in the file from your current cursor location.
So, the cursor location is crucial and should preferably be at the start.
The shortcut to take the cursor location at the start is "ALT+ \ ".
To search and replace, use "Ctrl+\ " and then enter the word you want to replace. Then enter the replacement and decide whether to replace specific matches or all matches.
领英推荐
Use Y or N to replace specific instances or A to replace all matching instances.
Activating Spellcheck
We can use spellchecking inside of Nano, but we have to enable it first in the Nano config file located at /etc/nanorc.
Use CTRL+W to search for spell and then un-comment the spell checker by removing # in front of it. And then save it using CTRL+O.
Using Spellcheck
Let's intentionally have our groceries.txt file with wrong spellings.
We can now use spellchecker by first going to the execute option (CTRL+T) and then using Spellcheck option (CTRL+S).
Options for words with correct spelling will be displayed you can select your option by entering the respective number of that word in the list. Do this for all the incorrect words and then save the file using Write Out option (CTRL+O).
Thanks for reading Feel free to connect : )