ChatGPT解决这个技术问题 Extra ChatGPT

Sublime text 2 - find and replace globally ( all files and in all directories )

Is there any way to find and replace text string automatically in all folder's files?


R
Riccardo Marotti

Yes, there is Multiple Files search and replace.

Press ctrlshiftF (cmdshiftF on MacOS):

https://i.stack.imgur.com/B7vVn.png

In the Where field you can also add filters to search only folders and files that you need. If nothing is set, the search is made on all files listed in the sidebar.

If you double click on a line of the search result, Sublime will jump to that line.

Notice these icons in the search bar:

https://i.stack.imgur.com/SJXOb.png

The first (show context) toggles context in result format (if enabled, some lines of text are shown before and after the matching line). The second allows to show the result in a new buffer, or in a console.


Is there a way to control which of the found cases in "Find in Files" get replaced? The Replace button does Replace_All.
I think that the only way is to use multiple files search to get the files you need to modify and then use normal search and replace (cmd+alt+F), file by file.
I don't pretend to know more than the creator of ST himself but you could just close the files (middle mouse click or ctrl+w) where you don't need the changes done and then click replace. Afterwards you can use Ctrl+Shift+t to reopen the closed files. You could also "add a exclude filter" clicking the button in the middle (the ellipsis) and write down the files where you don't want replacements.
If you put <project> in the "Where" field, it'll search recursively through all of the folders and files in the currently open project. You can also type in a relative path (e.g., search/for/things/here/ and it will only search through that folder, recursively, relative to your project's root. Very handy.
For this where field to come up by default with search and replace (ctrl+H) I added this to my user keybindings: { "keys": ["ctrl+h"], "command": "show_panel", "args": {"panel": "find_in_files"} }
M
Mike Lyons

Press ctrlshiftF (cmdshiftF on  Mac OS X :) and then put *.* in the where: field

This will open the search up to all files in the project as opposed to only open files or folders.

You can also use this to search only files of a certain type, or with a certain name regardless of type. It's just wildcards for the filename and extension.