Question

When I search multiple files via Command + Shift + F, the result is returned as something like a text file. This text file is editable, but changes made don't affect the original files.

Is it possible to do such that changes in "Find Results" propagates to the original source file?

Was it helpful?

Solution

The Find Results Apply Changes plugin was created to do just that.

You can install it through Package Control's "Install Package" option.

Before using this plugin, make sure that you have UTF-8 encoding enabled using the menu:

File > Save with Encoding > UTF-8

Once installed, you can apply any change you made to a "Find Results" buffer back to the files:

  • Search for "foo" in a folder (Sublime's default shortcut is CTRL+SHIFT+S)
  • This will open a "Find Results" buffer listing all the files with "foo" in it.
  • Change the instances of "foo" for "bar" or something else...
  • Go to the menu:

    Find > Find Results - Apply Changes
    
  • This will write all the changes made back to the files and save the modified files automatically.

By default, using menus is the only way to make it work. However, it is quite tiresome and doesn't save as much time as it does with a keyboard shortcut. You can set your chosen keyboard shortcut by adding a new line in

Preferences > Key Bindings - User

by adding:

{ "keys": ["ctrl+r"], "command": "find_results_apply_changes" },

Don't use CTRL+S as it will overwrite saving file shortcut.

Warning!: According to the author of the plugin:

Uses regions to allow you do multiline changes, but when inserting new newlines, will corrupt files if you commit more than once, this because the new newlines will shift the line numbers. Will also 'corrupt' files if you add/remove newlines in other instances of the modified files. eg in another tab. To prevent corruption this packages will alert you and prevent most of these.

(This is a modified version of the description from the Find Results Apply Changes Github page.)

OTHER TIPS

The shortest workaround I can think of would be to open the target file from search results by simply double clicking the path and then jumping to the according line using Ctrl+G on Windows or +G on Mac OS.

That's the way I do it and must say it is only a matter of seconds, even without the plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top