Sublime Forum

How can I search and replace across multiple files?

#1

OS X, Sublime Text 2.0.2 build 2221.

I’d like to understand how search-and-replace works in Sublime Text 2.

I’m especially interested in searching and replacing across multiple files.

The functionality I want is…

(1) To enter a string and its replacement string, execute the search, and then visit each result one at a time and either replace it or not according the situation.

(2) Also, sometimes I’d like to be able to just replace all instances of some string with some other string throughout several files in one operation.

I found this page in the “unofficial docs,” but it doesn’t explain how to do those things…

[sublime-text-unofficial-documen ... files.html](https://sublime-text-unofficial-documentation.readthedocs.org/en/sublime-text-2/search_and_replace/search_and_replace_files.html)

In practice, I hit Command-shift-F and enter the string and the replacement Sublime will present a buffer listing the files where the string occurrs and highlighting where it appears in the files.

According to the docs at the URL above you can go to the next match with F4.

When I press F4 Sublime opens the file and puts the cursor at the beginning of the line containing the match.

Then I guess I need to visually scan the line looking for the match? And then navigate to it and type in the replacement string? Is that how it’s supposed to work?

From other text editors and IDEs, I’m accustomed to visiting each result (the exact place in the file, not just the beginning of the line) and being able to optionally replace it or not and then move to the next exact result location.

Does Sublime have a way to do that? Or something close to that?

Thanks!

0 Likes

#2

Sublime can visit and replace each match in one file (with cmd+f), or replace all occurrences without visiting in all files (with cmd+shift+f). It cannot (as far as I know) visit all occurrences in all files.

0 Likes