问题描述
> 在文件中查找... + + ,您将被带到查找结果,列出文件和突出显示的匹配项。您可以双击文件名/路径或匹配的行来打开文件。
不知道是否有办法做到双击是否通过键盘?
使用Sublimes很好的文件切换功能,我认为在执行在文件中查找... 。
看来一个插件已经被创建来做到这一点。快速浏览一下,插件中还有一些额外的功能。尽管下面我的原始答案会起作用,但是安装现有的插件会容易得多。
可以使用插件。
import sublime
import sublime_plugin
import re
import os
class FindInFilesGotoCommand(sublime_plugin.TextCommand):
def run (self,edit):
view = self.view
if view.name()==查找结果:
line_no = self.get_line_no()
file_name = self .get_file()
如果line_no不是None并且file_name不是None:
file_loc =%s:%s%(file_name,line_no)
view.window()。open_file file_loc,sublime.ENCODED_POSITION)
elif file_name不是:
view.window()。open_file(file_name)
$ b def get_line_no(self):
view = self.view
如果len(view.sel())== 1:
line_text = view.substr(view.line(view.sel()[0]))
match = re.match(r\s *(\d +)。+,line_text)
如果匹配:
return match.group(1)
return None
$ b $ 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 os。 path.exists(match.group(1)):
return match.group(1)
line = view.line(line.begin() - 1)
return None
使用 find_in_files_goto 命令设置键绑定。这样做时要小心。理想情况下,会有一些设置将此视图标识为在文件中查找视图,因此您可以将其用作上下文。但我不知道一个。当然,如果你找到一个,请告诉我。
编辑
将示例键绑定到主体答案。
$ $ $ $ $ $ $ $ $ $ $ $ $$ :find_in_files_goto,
context:[{
key:selector,
operator:equal,
operand:text。 find-in-files
}]
}
If you File > Find in Files... ++ you're brought to the Find Results, listing the files and highlighted matches. You can double-click either the filename/path or the matched line to open the file at the right line.
I wonder if there is a way to do exactly what the double-click does via keyboard?
With Sublimes great file switching capabilities, I thought there must be a way to keep your hands on the keyboard when doing Find in Files....
It appears a plugin has been created to do this. Took a quick look, there are some additional features in the plugin. While my original answer below will work, it will be much easier to install an existing plugin.
https://sublime.wbond.net/packages/BetterFindBuffer
Doable with a plugin.
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
Set up a key binding with the command find_in_files_goto. Be careful when doing this though. Ideally, there would be some setting that identifies this view as the "Find In Files" view, so you could use that as a context. But I'm not aware of one. Of course, if you do find one, let me know.
EditPulling up the example key binding into the main body of the answer.
{ "keys": ["enter"], "command": "find_in_files_goto", "context": [{ "key": "selector", "operator": "equal", "operand": "text.find-in-files" }] }
这篇关于崇高的文本:如何跳转到使用键盘查找结果文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!