Skip to main content

Nano Essentials

Search and Replace in Nano

Like any other editor, Nano provides the search and replace feature. Here's how to use it.

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 + W key combination
  • To start a search and replace, use Alt+R key combination

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.

search for text in GNU nano
DigitalOcean – The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size – faster than ever before.

Get started on DigitalOcean with a $100, 60-day credit for new users.

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?"

  • Y : Yes
  • N : No
  • A : All
  • ^C : Cancel (the ^ symbol means usage of 'Ctrl' key)
substitute text functionality in GNU nano
Best Text Editors for Linux Command Line
These are the best editors in Linux when you go command line.

Conclusion

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.

Team LHB