Ctrl+Shift+h to find and replace in all scripts

I remember seeing a post on Twitter about a plugin which allowed you to do this, I can’t remember where though.

2 Likes

Get all the scripts you want to change, then switch out the keyword using a string modifier on Script.Source.

I just wrote this little script. I think it works. It collects all scripts, then runs gsub to match and replace the source. It’s not tested though. Also, I don’t remember if you’re supposed to put the SetWaypoint thing before or after:

game:GetService("ChangeHistoryService"):SetWaypoint("ChangeScripts")


local FIND_PATTERN = "foo"
local REPLACE_WITH = "bar"

local services = {
	game.Workspace,
	game:GetService("ReplicatedFirst"),
	game:GetService("ReplicatedStorage"),
	game:GetService("ServerScriptService"),
	game:GetService("ServerStorage"),
	game:GetService("StarterGui"),
	game:GetService("StarterPlayer"),
	game:GetService("Lighting")
}

function GetAllScripts()
	local scripts = {}
	for _,service in pairs(services) do
		for _,child in pairs(service:GetDescendants()) do
			if (child:IsA("LuaSourceContainer")) then
				scripts[#scripts + 1] = child
			end
		end
	end
	return scripts
end

function FindAndReplace(targetScript)
	targetScript.Source = targetScript.Source:gsub(FIND_PATTERN, REPLACE_WITH)
end

for _,s in pairs(GetAllScripts()) do
	FindAndReplace(s)
end

Disclaimer: Use at your own risk. I would be cautious about executing code that can change your source code. I added the history waypoint though just for safe measure. If this messes up your scripts, please don’t hurt me :stuck_out_tongue:

If you want to improve this, turn the GetAllScripts function into an iterator.

12 Likes

Before, so you’re good.

1 Like

Thanks so much!

1 Like

Sure thing. But it would still be nice to have a built-in feature to do this. Would be easy to wrap my code into a plugin though, and use UserInputService to bind some sort of shortcut. Then you’d have to build a small UI for it too.

2 Likes

Also there should be a replace with regular expression. Example, {‘1’,‘2’} becomes “1” & “2” through 1 regular expression, reusing the original values, replacing the apostrophes.

1 Like

This is a much needed feature!

1 Like

Yes please! I was dealing with this annoyance only last week, thinking those exact words to myself the whole time.

We need this now!

2 Likes

Bumping this because we never heard any feedback on it and there’s no need to create a new thread. I came back to an old project and wanted to restructure how my modules are stored, and that means changing the code in every script that calls that module everytime I move one! Why isn’t this a feature? Is there a plugin for it, like the code @crazyman32 provided?

1 Like

There is some low-hanging fruit we can pluck with the Script Editor. We are looking at a list of them now. Hopefully more on this soon.

5 Likes

This was intended to be a new topic, but it was approved as a reply. Here is my arguments for why this should be added, because it’s still a much needed feature in Studio.


Introduction

As a developer, it is currently hard to replace all occurrences of the same value across multiple scripts. If we had Replace All as an option, it would be easier and make workflow much smoother.


Why should it be added?

We currently have access to replacing all in the current scope (the script we’re viewing), but not across all scripts. Furthermore, we can also use CTRL + SHIFT + F to Find All across all scripts.

There have been multiple instances when I’ve needed to change multiple occurrences over multiple scripts, but have had to do it separately due to the fact that there hasn’t been an option like this. Not only does this slow down progress, it also makes mass bug fixing tedious.

Even when you make a minor error that you’ve put out in multiple scripts (probably my fault for bad practices), it’s still a painful task that requires a lot of effort to fulfil.


What would it look like?

Similar to the Find All shortcut:
image
Shortcut could be CTRL + SHIFT + H, unless something else has occupied that.


Conclusion

I’m sure this would probably benefit at least some people, myself included.

What this allows us to do:

  • Quickly fix bugs that have been pushed out across all scripts
  • Find and replace all occurrences of a mistake that you’ve rolled out across multiple scripts
  • Save time looking, improve workflow and dedicate that time to improving other aspects of your game, rather than focusing on pain-staking tasks, such as this.
7 Likes

Here’s a really good plugin that will remedy the lack of this feature;

4 Likes

Bump due to relevance; it should be simple to implement and will speed up scripting workflow.

Can’t put it any better than @Polyheximal has

Necrobump


This feature already exists, simply do Ctrl + Shift + F and then press the dropdown menu. Which will give you your find and replace all.

It doesn’t accurately find the contents of the script. If you try selecting all the code in a script then using Ctrl + Shift + F you get no results

Also what’s the point of declaring that my post is a bump? I’m not asking defensively I’m just curious

But on looking upon it again I see this feature request should probably be closed now since the feature was added. However, I could open a bug report for the Find All not functioning right

1 Like

Probably should’ve explained that more in my original post. Since the feature described in the original post has already been implemented for the most part, it’d be best to create a new topic for any additional features that are wanted. Comments / additional requests here will most likely be lost, since readers are less likely to be read all the comments as the original requested feature has already been implemented.


I would agree that it seems what you found is most like a bug since the normal find and replace within a single script accounts for new lines properly, but not in Find All and Replace All.

Yeah! I’m sorry, I actually completely misunderstood this thread when I bumped it.

I had multiple copies of qPerfectionWeld scripts in my game(Eventually I’ll reorganize it into a single module but for now I have many copies) that I wanted to update. Since Ctrl + Shift + F-ing the script content wasn’t returning results, I assumed it just wasn’t intended for searching entire scripts. Therefore I looked for a feature request for searching whole scripts and stumbled upon this one.

I now realize Studio is probably supposed to support this action, but a bug is preventing that. If I had known that I would’ve uploaded a bug report with this post linked instead of bumping this post.

Thanks for bringing this to my attention! I’ll read posts more carefully going forward

Also I’m gonna make a bug report for this problem I discovered if there isn’t one already :)