How to edit multiple files through "Find results" in Sublime Text

Adam Pietrasiak picture Adam Pietrasiak · Nov 7, 2013 · Viewed 8k times · Source

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?

Answer

Rafal picture Rafal · May 7, 2014

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.)