简体   繁体   English

如何通过Sublime Text中的“查找结果”编辑多个文件

[英]How to edit multiple files through “Find results” in Sublime Text

When I search multiple files via Command + Shift + F , the result is returned as something like a text file. 当我通过Command + Shift + F搜索多个文件时,结果将返回为类似文本文件的内容。 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? 是否可以将“查找结果”中的更改传播到原始源文件?

The Find Results Apply Changes plugin was created to do just that. 创建查找结果应用更改插件是为了做到这一点。

You can install it through Package Control's "Install Package" option. 您可以通过Package Control的 “安装包”选项安装它。

Before using this plugin, make sure that you have UTF-8 encoding enabled using the menu: 在使用此插件之前,请确保使用菜单启用了UTF-8编码:

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 ) 在文件夹中搜索“foo”(Sublime的默认快捷键是CTRL + SHIFT + S
  • This will open a "Find Results" buffer listing all the files with "foo" in it. 这将打开一个“查找结果”缓冲区,列出其中包含“foo”的所有文件。
  • Change the instances of "foo" for "bar" or something else... 将“foo”的实例更改为“bar”或其他内容......
  • 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. 不要使用CTRL + S ,因为它将覆盖保存文件快捷方式。

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.) (这是查找结果应用更改 Github页面中描述的修改版本。)

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. 我能想到的最短的解决方法是从搜索结果中打开目标文件,只需双击路径,然后使用Windows上的Ctrl + G或Mac OS上的^ + G跳转到相应的行。

That's the way I do it and must say it is only a matter of seconds, even without the plugin. 这就是我这样做的方式,必须说它只是几秒钟,即使没有插件也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM