Black Friday Deals for Linux Users are Now Live!
Learn more
Sep 26, 2022 3 min read

How to Search and Replace (Substitute) Text in GNU Nano Editor?

Table of Contents

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.

Linux Foundation Training
Team LHB
Team LHB indicates the effort of a single or multiple members of the core Linux Handbook team.
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Linux Handbook.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.