Home Download Buy Blog Forum Support

Search and replace only in selected files

Search and replace only in selected files

Postby zoopzoop on Thu Jul 12, 2012 1:07 pm

I recently switched to ST from TextMate and I'm really enjoying it so far!
The only thing I'm struggling with is the Search and replace functionality which I tend to use a lot.
I know that ST has a lot of cool possibilities to replace multiple occurrences of a string with multi-selection and such, but sometimes I just need to do the following:

* Search for a string in all files of the current project
* Select a few files where the string was found
* Replace the string for something else only in the selected files

It's the bold bit I'm struggling with. From the "Find Results" window, how can I only select a few files or occurrences and replace those?
Any ideas or workarounds are appreciated! :)
zoopzoop
 
Posts: 7
Joined: Thu Jul 12, 2012 1:03 pm

Re: Search and replace only in selected files

Postby tito on Thu Jul 12, 2012 3:50 pm

Some of the features you mention included in https://github.com/titoBouzout/SideBarEnhancements
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 876
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Search and replace only in selected files

Postby zoopzoop on Sat Jul 14, 2012 11:56 am

I have the SideBarEnhancements plugin installed but I don't see how that could help me...
To clarify: I want to search for a term in the whole project first but then replace only some occurrences which I ideally would like to select in the search results.
zoopzoop
 
Posts: 7
Joined: Thu Jul 12, 2012 1:03 pm

Re: Search and replace only in selected files

Postby eyewinder on Sat Jul 14, 2012 6:35 pm

I'm also a new ST user (from TextMate) and have found the search & replace in "Find in files..." a bit intimidating and frustrating (especially if there are a large number of search results).

Currently, I'm resorting to opening individual files from the Find Results and running the replace command manually. This certainly isn't very efficient, so I'm hoping there is an easier way too!

BTW, I'm also using SideBarEnhancements...
eyewinder
 
Posts: 2
Joined: Sat Jul 14, 2012 5:53 pm

Re: Search and replace only in selected files

Postby LaserFace on Sun Jul 15, 2012 3:42 am

I don't have the sidebar enhancements. But I just found that if I go to Find > Find In Files (Ctrl + Shift + F), type in the string to find, click the ellipses and add whatever folders and files you want, and then click the ellipses again and add an exclude filter and type in the file names of files you don't want to replace the string with, and it worked for me.

Not sure how well this method is for really large projects. It would be nice to add some more functionality to the 'exclude filter' option so that you can select from a list what you want to exclude, but not sure if that plugin has been written yet...
LaserFace
 
Posts: 14
Joined: Sun Jul 15, 2012 3:06 am

Re: Search and replace only in selected files

Postby zoopzoop on Sun Jul 15, 2012 1:07 pm

LaserFace wrote:I don't have the sidebar enhancements. But I just found that if I go to Find > Find In Files (Ctrl + Shift + F), type in the string to find, click the ellipses and add whatever folders and files you want, and then click the ellipses again and add an exclude filter and type in the file names of files you don't want to replace the string with, and it worked for me.

Not sure how well this method is for really large projects. It would be nice to add some more functionality to the 'exclude filter' option so that you can select from a list what you want to exclude, but not sure if that plugin has been written yet...


Yeah, that's what I have been doing as well. It basically forces you to search twice, though.
1. Seach for "foo", see in results that it exists in files in folders A, B and C. If you just want to replace the occurrences in A and B
2. search again, excluding C, and replace.

But what if I want to replace "foo" in just a few files in folder A, not in all of them. Then I have to open them all individually, as eyewinder mentioned.

I think Textmate's solution for this is really nice, where you can select individual files or whole folders in the search results and just do the replace on them.
zoopzoop
 
Posts: 7
Joined: Thu Jul 12, 2012 1:03 pm

Re: Search and replace only in selected files

Postby eyewinder on Sun Jul 15, 2012 5:46 pm

Yes! The double searching only makes it more time consuming...

It would be nice if the find and replace panel had a "sticky" option – remaining open unless dismissed. It would also be useful to have a option to flush the previous search buffer output, so the Find Results don't get overly cluttered.

Of course, these suggestions don't address the main issue of including just a few files for replace actions – rather than the complicated process of excluding many files.

Maybe this could be addressed with dedicated "Include" and "Exclude" text fields with support for autocomplete (like Goto Anything...), regular expressions and drag and drop? Just a few random thoughts...
eyewinder
 
Posts: 2
Joined: Sat Jul 14, 2012 5:53 pm

Re: Search and replace only in selected files

Postby pkmiec on Tue Jul 17, 2012 4:38 pm

I'm also a TextMate convert and running into this inconvenience.

TextMate also allows you to collapse all search results to be able to see the files that were matched. I find this very useful when searching for something that will have lots of matches and intuitively knowing which files i'm not interested in. This is much easier than trying to figure out the right include / exclude filters.
pkmiec
 
Posts: 1
Joined: Tue Jul 17, 2012 4:31 pm

Re: Search and replace only in selected files

Postby LaserFace on Thu Jul 19, 2012 5:04 am

I'm a Windows user and unfortunately I can't check out TextMate.

I also did not realize how much I needed this feature until tonight!
LaserFace
 
Posts: 14
Joined: Sun Jul 15, 2012 3:06 am

Re: Search and replace only in selected files

Postby gregors on Sat Jul 21, 2012 8:04 am

I believe it does have this feature.

Look under find in files, the middle box is "where" , you can use regex like expressions in this box.

Use the ... And it has some options, add folder, add include filter, exclude, open folders, open files.

I couldn't find too much documentation on this though.

This of course assumes the files follow some kind of naming pattern.

Check it out!
gregors
 
Posts: 4
Joined: Fri Jul 20, 2012 6:24 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 13 guests