Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text: interactive confirm for replace?

I need to do a lot of search/replace across 50+ files, and am using Sublime Text 3.

Is there a way to step through and interactively confirm each change? I dont't want a blanket Replace All action that just performs all replacements.

I am thinking way back to vi/vim with its %s/old/new/gc functionality.

like image 927
Daniel Smith Avatar asked Feb 03 '15 18:02

Daniel Smith


1 Answers

Both the Find/Replace and Find in Files/Replace commands don't natively support prompting you if the replacement should happen. Regular in-buffer find/replace just replaces directly and the only confirmation that you can get is when you do a Find in Files and Sublime prompts you to confirm the replacement after telling you how many replacements will be made.

As such, the only way to get something like this is to look to an external plugin/package that would do it's own find and replace option so that you could be asked to confirm the changes.

I'm not personally aware of any packages that would do this, but a search in Package Control turns up the RegReplace package, which lists among its features:

Create commands that highlight results and requiring confirmation before replacing.

That said I've never used the package myself, and from briefly looking at the documentation site it seems like it's only capable of searching in the current document and not across files.

A potential workaround would be to use the native Find in Files to find all files with matches, then manually open them and use RegReplace to perform the same operation again.

like image 186
OdatNurd Avatar answered Nov 19 '22 02:11

OdatNurd