Nano is a very compact and feature packed text editor commonly found on Linux and Unix based OS. One of the lesser used feature that is very useful is search & replace.
To Search and Replace text in the currently open file:
Press Ctrl + \ Enter your search string [return] Enter your replacement string [return] Press A to replace all instances
The search string can also be a regular expression.
instead of CTRL \ you could use ALT + R
Many thanks mate.
the better answer, if you use a non-english keyboard layout! Thanks, mate
Not sure if I am the only one but i found that the only way I could toggle the regex search was to M-R while in the Search function (i.e. ^W)
Works like a cham 🙂
what is M-R? I was trying to do a global replace but did not see the command for replace all just M-R
In some VPS is impossible to use “Ctrl + \”, instead you can use “Ctrl + W” and then “Ctrl + R”.
Thanks so much, this was the tip I was looking!
Best command! Many thanks!
The only site that showed me the correct command for a mac os. Thanks!
And how can we make changes in multiple files in directory?
Try this
grep -rli “my text” * | xargs -i@ sed -i ‘s/my text/new text/g’ @
Need to do a “search and destroy”. i.e.
1. delete all lines beginning with (delete, NOT replace)
2. delete all instances of . (delete, NOT replace)
Just live the second input field blank