Replace in files

Is it me or there is no “replace in files” in the editor?

Nope, I don’t think there is!

1 Like

My favorite substitute for this is:

  1. Highlight the text you wish to change throughout a file.
  2. Press CTRL + D repeatedly (best feature to ever be implemented in any software ever).
  3. Type your new text!
1 Like

Yes, thanks! I already use that! One of my best friends!

But I am looking for “replace in files”. I have to change a string in ALL files of the projects with a certain extension.

Perhaps you want to avoid external software for this, but I keep Notepad++ solely for how much I like the replace in files functionality.

5 Likes

Similarly, I use Sublime Text for this. Poor Sublime Text.

2 Likes

Thanks!

I have used “sed” via command line. I don’t understand very well this kind of magic, but it worked! :slight_smile:

2 Likes

You could open the project in vscode, find all and replace all, but you should do it with your own risk, because it is treating it as plain text.

1 Like

Easy. Look at this sample with two files (will work with any numbers of files, of course):

/tmp$ for i in *.lua; do echo "$i";cat "$i";echo "****";done
titi.lua
print "it's still me"
****
toto.lua
print "It's me"
****

Now you want to replace me by you :

/tmp$ sed -i 's/me/you/' *.lua

The -i parameter of sed means « replaces in place » (directly in the file).

The files have to be in the same directory, but you can easily combine it with find to find and modify in a complex tree file structure.

Result:

/tmp$ for i in *.lua; do echo "$i";cat "$i";echo "****";done
titi.lua
print "it's still you"
****
toto.lua
print "It's you"
****
1 Like

There is also Geany that can do this.

1 Like