Sublime Text打开包含搜索词的所有文件

Sco*_*ttF 5 sublimetext sublimetext2 sublimetext3

当我按ctrl + shift + F搜索当前范围内的所有文件时,我会得到一个新窗口,列出包含该搜索词的所有文件.

如何快速打开所有这些文件?

Vig*_*ant 17

按住搜索结果屏幕中的F4键,它将"导航到下一个匹配项" - 这将使其打开结果中列出的每个文件.

只是一个小小的注释,如果你每个文件得到10多个匹配,这个方法开始失败,因为它变慢了.

  • 这个答案是完美的. (3认同)
  • 在Windows中工作。崇高文字2- (2认同)

Oda*_*urd 5

Sublime没有开箱即用的功能;但是,插件API使您能够创建一个插件来完成类似这样的操作(取决于最终的工作方式)。

我假设有类似这样的插件可用,但出于参考目的,这是一个简单的示例:

import sublime
import sublime_plugin

class OpenAllFoundFilesCommand(sublime_plugin.TextCommand):
    def run(self, edit, new_window=False):
        # Collect all found filenames
        positions = self.view.find_by_selector ("entity.name.filename.find-in-files")
        if len(positions) > 0:
            # Set up the window to open the files in
            if new_window:
                sublime.run_command ("new_window")
                window = sublime.active_window ()
            else:
                window = self.view.window ()

            # Open each file in the new window
            for position in positions:
                window.run_command ('open_file', {'file': self.view.substr (position)})
        else:
            self.view.window ().status_message ("No find results")
Run Code Online (Sandbox Code Playgroud)

这提供了一个名为的命令open_all_found_files,该命令可以绑定到键,添加到菜单,添加到命令面板等。

使用sublime对查找结果具有自定义语法的概念,该结果具有专用于匹配文件名的作用域,这将收集所有此类区域,然后打开关联的文件。

new_window可以传递可选的参数,并将其设置为true在新窗口中打开文件。保留它或将其设置false为在与查找结果相同的窗口中打开文件。当然,您可以根据需要更改默认值。