Editing files with nano

In this article, we would cover – editing files with nano. If you have been following us along – then you must have noticed that we have used nano text editor prominently. So, this time around we thought of explaining its couple of features.

nanoNano’s ANOther editor. It is inspired by Pico (which is a text-editor itself). interactive search and replace, undo/redo, syntax coloring are few of the features offered.

Launching nano

We first start with launching nano. Just open a terminal and issue the following –

nano

It will open the text-editor. Since, we haven’t opened a file. Therefore, at the top it says – New Buffer. After we are finished working/writing, it would ask us to save the file. But, we can open an existing file too, just use –

nano abc.txt

where, abc.txt is the text file. Make necessary changes and save the file.

To save the contents of the file we use Ctrl+O (this is to write out). At this stage, if its a new file then, it will ask for the file name to write. Provide the file name and press Enter.

It would now show us how many lines have been written. Thereafter, do Ctrl+X to exit. It is worth mentioning here that, it will save the file in the directory from which you have opened the terminal.

Now, that you know how to launch and exit the nano text-editor. We move to the editing the files next.

Editing files with nano

To cut a line, use Ctrl+K. Thereafter, to paste the same move the cursor to the desired location and do Ctrl+U.

To search for a specific word, we use Ctrl+W. It will ask us what to search. Provide the search term and press Enter. It will highlight the search term and move us to its location. Use F6 and Enter for multiple searches.

Use Ctrl+\ to replace a word. It asks for the word/letter to replace. Thereafter, the word/letter which it should be replaced with. Lastly, whether we want to replace all or only the specific ones. Press A to replace all or simply provide Y or N for specific replacements.

In conclusion, we have discussed nano text editor here. We mainly covered launching and exiting nano text-editor. How to cut an entire line and paste it to desired location. Apart from that, we also covered search and replace. Since, its not possible to cover the entire text editor like nano in single article, so we will discuss the nano text-editor in subsequent articles as well.

Similar Posts