Sublime Text:如何使用键盘从查找结果中跳转到文件?

muh*_*hqu 51 find sublimetext sublimetext2 sublimetext3

如果你File> Find in Files... + + F你被带到了Find Results,列出文件和突出显示的匹配.您可以双击文件名/路径或匹配的行以在右侧打开文件.

我想知道是否有办法完全通过键盘进行双击?

凭借Sublimes出色的文件切换功能,我认为必须有一种方法可以让您在操作时保持键盘Find in Files....

Chr*_*yer 58

尝试Shift+ F4(铝键盘上的fn+ Shift+ F4).

  • 我正在测试并使用普通F4打开下一个结果文件 (5认同)
  • 映射到`prev_result`命令的F4比`next_result`效果好得多,但它并不总能产生相同的效果.如果您处于"查找结果"缓冲区并重复转到相同的搜索结果,则不会将您带到光标下方的结果中.然后它会像命令名称建议的那样运行,并将您带到之前的结果.虽然这是一个小问题,但我会坚持@skuroda的插件,它总是表现得像预期的那样.无论如何,谢谢你的回答! (3认同)
  • 这应该是公认的答案,因为它可以在不需要插件的情况下完成用户的要求.希望默认值比shift-F4更直观. (3认同)

sku*_*oda 28

看来已创建了一个插件来执行此操作.快速浏览一下,插件中还有一些其他功能.虽然我的原始答案可行,但安装现有插件会容易得多.

https://sublime.wbond.net/packages/BetterFindBuffer


可以使用插件.

import sublime
import sublime_plugin
import re
import os
class FindInFilesGotoCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        if view.name() == "Find Results":
            line_no = self.get_line_no()
            file_name = self.get_file()
            if line_no is not None and file_name is not None:
                file_loc = "%s:%s" % (file_name, line_no)
                view.window().open_file(file_loc, sublime.ENCODED_POSITION)
            elif file_name is not None:
                view.window().open_file(file_name)

    def get_line_no(self):
        view = self.view
        if len(view.sel()) == 1:
            line_text = view.substr(view.line(view.sel()[0]))
            match = re.match(r"\s*(\d+).+", line_text)
            if match:
                return match.group(1)
        return None

    def get_file(self):
        view = self.view
        if len(view.sel()) == 1:
            line = view.line(view.sel()[0])
            while line.begin() > 0:
                line_text = view.substr(line)
                match = re.match(r"(.+):$", line_text)
                if match:
                    if os.path.exists(match.group(1)):
                        return match.group(1)
                line = view.line(line.begin() - 1)
        return None
Run Code Online (Sandbox Code Playgroud)

使用该命令设置密钥绑定find_in_files_goto.这样做时要小心.理想情况下,会有一些设置将此视图标识为"在文件中查找"视图,因此您可以将其用作上下文.但我不知道一个.当然,如果你找到了,请告诉我.

编辑 将示例键绑定到答案的主体中.

{
    "keys": ["enter"],
    "command": "find_in_files_goto",
    "context": [{
        "key": "selector",
        "operator": "equal",
        "operand": "text.find-in-files"
    }]
}
Run Code Online (Sandbox Code Playgroud)

  • 哦......当然,您可以将键绑定限制为仅适用于"查找结果"视图.您可以检查范围`text.find-in-files`.例如`{"keys":["enter"],"command":"find_in_files_goto","context":[{"key":"selector","operator":"equal","operand":"text. find-in-files"}]}` (2认同)
  • 很棒的插件.有人将其主题化为Monokai吗? (2认同)

Som*_*dar 19

SublimeText 3我不得不使用F4(用于将当前结果文件)和Shift +F4(对于以前的结果).

从默认的keymap ...

{ "keys": ["super+shift+f"], "command": "show_panel", "args": {"panel": "find_in_files"} },
{ "keys": ["f4"], "command": "next_result" },
{ "keys": ["shift+f4"], "command": "prev_result" },
Run Code Online (Sandbox Code Playgroud)

我希望这篇文章有所帮助.

SP


rob*_*son 11

命令'next_result'将执行此操作.使用关于使用范围的简洁想法muhqu,您可以使它在您想要转到的行上按"输入":

,{ "keys": ["enter"], "command": "next_result", "context": [{"key": "selector", 
"operator": "equal", "operand": "text.find-in-files" }]}
Run Code Online (Sandbox Code Playgroud)


小智 7

尝试Ctrl + P - 这会在项目中按名称快速打开文件,有关键盘快捷键的完整列表,请参阅此处

  • 这对于找到的结果有何帮助? (2认同)