Sublime Forum

Edit 'Find Results' tab and save directly into the files

#1

I have seen several posts that suggest this can be done, but as yet I have not found one that actualy works!..
On a project with many files and folders I used ‘Find in Files’ to find something like “G98” know ing there would be quite a few instances - There was! the Results tab was several pages long.
What I want to be able to do is edit the entries in the Results tab (easy) but then enter some command or keystroke to save all the changes I made directly into the actual files themselves (difficult !).
It should really be an actual Sublime function in my opinion?

0 Likes

#2

I haven’t tried it myself, but maybe
https://packagecontrol.io/packages/FindResultsApplyChanges

0 Likes

#3

That looks perfect for what I want to do?
But… How the hell do I actually get it into ST???

0 Likes

#4

And working?

0 Likes

#5

If you are using ST4 then you can’t as the package is for ST3.

0 Likes

#6

Thanks for confirming my suspicions. It’s a shame, it would be such a good feature. I still think it should be a standard feature that should be easy to add for sublime hierarchy?

0 Likes

#7

ST4 is backwards compatible with ST3, most plugins should work without issue. In this case the plugin doesn’t work because we’re changed from displaying: /home/bschaaf/some_file.txt to ~/some_file.txt.

A simple fix makes that plugin work again:

--- a/FindResultsApplyChanges.py
+++ b/FindResultsApplyChanges.py
@@ -134,8 +134,9 @@ class FindResultsApplyChangesCommand(sublime_plugin.TextCommand):
             modified_files = 0
             for f in changes:
                 f = f.strip()
-                if f and changes[f] and os.path.exists(f):
-                    content = self.read(f).split("\n")
+                path = os.path.expanduser(f)
+                if f and changes[f] and os.path.exists(path):
+                    content = self.read(path).split("\n")
                     modified = False
                     for k in changes[f].keys():
                         k = int(k)
@@ -147,7 +148,7 @@ class FindResultsApplyChangesCommand(sublime_plugin.TextCommand):
                                 )
                             modified = True
                     if modified:
-                        self.write(f, "\n".join(content))
+                        self.write(path, "\n".join(content))
                         modified_files += 1
             if modified_files:
                 sublime.status_message(
1 Like

#8

Many, many thanks to you for that; I wish I had your obvious knowledge! I could now do with some more information to help me actually install and run the package…
I downloaded the package via ‘packagecontrol.io’ and ‘GitHub’ this gave a zipped file ‘FindResultsApplyChanges.zip’ within this .zip file were 3 sublime-keymap files, two python files (1 with the same same as the .zip), 1 windows batch file and 1 MD file.
I applied all the changes you posted to the main python file and saved it… so good so far.
What do I have to do now with the resultant modified .zip file and where do I need to put it within the sublime folders hierarchy for sublime to then see it?
If I call up the command palette and type ‘install packages’ I see an extensive list of packages, but not the one I want.
I’m obviously missing something. Sorry to sound a bit thick but I am getting on and the old brain does’nt quite work like it used to!
Thanks so far.

0 Likes

#9

You can either change the extension of the modified zip file to .sublime-package and place it in the folder opened by the menu Preferences > Browse Packages…. Or you can extract the zip file into a folder in the same location (ie. Packages/FindResultsApplyChanges/FindResultsApplyChanges.py)

0 Likes