代码之家  ›  专栏  ›  技术社区  ›  ForgetfulFellow

升华-键盘快捷键转到“在文件中查找”的第一个选择

  •  1
  • ForgetfulFellow  · 技术社区  · 7 年前

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  2
  •   OdatNurd    7 年前

    Find > Find Results

    除了通常的文件导航之外,没有任何导航键可以在find-in-files输出中跳转,但是您可以通过插件添加这样的导航键:

    import sublime
    import sublime_plugin
    
    class JumpToFindMatchCommand(sublime_plugin.TextCommand):
        """
        In a find in files result, skip the cursor to the next or previous find
        match, based on the location of the first cursor in the view.
        """
        def run(self, edit, forward=True):
            # Find the location of all matches and specify the one to navigate to
            # if there aren't any in the location of travel.
            matches = self.view.find_by_selector("constant.numeric.line-number.match")
            fallback = matches[0] if forward else matches[-1]
    
            # Get the position of the first caret.
            cur = self.view.sel()[0].begin()
    
            # Navigate the found locations and focus the first one that comes
            # before or after the cursor location, if any.
            pick = lambda p: (cur < p.begin()) if forward else (cur > p.begin())
            for pos in matches if forward else reversed(matches):
                if pick(pos):
                    return self.focus(pos)
    
            # not found; Focus the fallback location.
            self.focus(fallback)
    
        def focus(self, location):
                # Focus the found location in the window
                self.view.show(location, True)
    
                # Set the cursor to that location.
                self.view.sel().clear()
                self.view.sel().add(location.begin())
    

    这将实现一个新命令 jump_to_find_match 这需要一个可选的参数 forward 以确定跳转是向前还是向后,并根据文件中第一个光标的光标位置将视图集中在下一个或上一个查找结果上,根据需要进行换行。

    Shift+Tab键 钥匙;钥匙 context

    {
        "keys": ["tab"],
        "command": "jump_to_find_match",
        "args": {
            "forward": true
        },
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.find-in-files", "match_all": true },
        ],
    },
    
    {
        "keys": ["shift+tab"],
        "command": "jump_to_find_match",
        "args": {
            "forward": false
        },
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.find-in-files", "match_all": true },
        ],
    },
    

    这将允许您在“查找”面板中的匹配项之间导航,但您仍然必须使用鼠标才能实际跳转到相关文件中的匹配项位置。

    通过键盘,你可以使用 this plugin ,它实现了一个模拟在光标位置双击的命令。下面这样的键绑定会触发命令以响应 输入 键,只要光标位于查找匹配项上:

    {
        "keys": ["enter"],
        "command": "double_click_at_caret",
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.find-in-files", "match_all": true },
        ],
    },
    
        2
  •  0
  •   goe1zorbey    5 年前

    F4 是你想要的答案。 Shift+F4 向后搜索。对应 next_result prev_result 是默认键绑定的一部分。

        { "keys": ["f4"], "command": "next_result" },
        { "keys": ["shift+f4"], "command": "prev_result" },
    
        3
  •  0
  •   DanielBlazquez    4 年前

    试着使用 Use buffer 按钮以在新选项卡中打开结果。

    推荐文章