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

We have Ctrl+Shift+f for find in all scripts, but nothing for find and replace. I think it’d be a handy addition to have, so why not?

96 Likes

oh my god yes PLEASE

4 Likes

or perhaps find and replace in selected scripts?

5 Likes

100% Support!!!

Currently I always need to use find all and then replace in each script that it matches.

7 Likes

This.

Definitely support!!

1 Like

You can SEARCH ALL? Wow, I need to research key combos

Already exists. Ctrl+h in script editor.

5 Likes

Not what I meant. That’s replacing in opened scripts, not selected scripts. CTRL + Shift + H should replace in all scripts that you’ve selected.

1 Like

I think replacing in all scripts is more useful than selected scripts, but that also sounds useful. Maybe it could be bound to something else.

1 Like

Replacing in all scripts is not very flexible. It’ll cause lots of debugging in most cases, whereas replacing in selected scripts makes it more custom and better manageable.

Say you have a lot of scripts that have similar variable usage and certain variables are replaced by, for example, a string. It’ll cause so much debugging if you have many scripts. You can avoid this by making this function only replace selected scripts, so you can limit the amount of debugging it’ll create.

Replace phrase in all scripts

As a Roblox developer, it is currently too hard to replace keywords in all scripts at once, instead you have to open each script and use ctrl + h to replace the keyword.

If this feature was added it’d make changing key words in scripts easier, instead of having to open each script and replacing the word with ctrl + h. This could be used to change a certain string in all the scripts at once.

3 Likes

Not the first post about this.

2 Likes

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