Any text editor that you might have used must have had the functionality to search for text and also replace the searched text with something else - often called text substitution.
And just like any other text editor, GNU nano has the functionality to search for text, and even replace the text you searched for.
- To search for text, use the
Ctrl + Wkey combination
- To start a search and replace, use
To learn more about GNU nano's search and substitution functionality, continue reading.
Searching for text in Nano
When you search for some text in GNU nano, it will move your cursor to the beginning of the searched text (that had the first match) you searched for.
To search for something, press the
Ctrl + W key combination. Doing so will bring up a bottom bar asking you what to search for. Type in the text you want to search for, and press the "Enter" key.
Once you press Enter, it will start searching. Upon the first match, your cursor will be moved to the beginning of that text (that was matched first).
If you want to see the next match, press
Ctrl + W again and when prompted to type text, simply press Enter. That will show the next match.
Find and replace text (substitution of text) in Nano
The functionality of text substitution involves searching for text, but not the way you thought.
To substitute text, press the
Alt + R key combination (for Mac people, it is
Ctrl + \ key combination). When pressed, it will ask for the text that you want to search for, so type the text in and then press the 'Enter' key. After that, enter the text that you want to replace it with.
Once you have specified the text to search for and the text that you want to replace it with, now GNU nano will highlight the first instance.
After that, you will be presented with four options with the question "Replace this instance?"
^C: Cancel (the
^symbol means usage of 'Ctrl' key)
The searching functionality in GNU nano is something every user of GNU nano should know about. And this article covers how to search and substitute text in nano.