sublimetext2 - Sublime Text: How to jump to file from Find Results using keyboard? -
if file
> find in files...
⇧+⌘+f you're brought find results
, listing files , highlighted matches. can double-click either filename/path or matched line open file @ right line.
i wonder if there way double-click via keyboard?
with sublimes great file switching capabilities, thought there must way keep hands on keyboard when doing find in files...
.
it appears plugin has been created this. took quick look, there additional features in plugin. while original answer below work, easier install existing plugin.
https://sublime.wbond.net/packages/betterfindbuffer
doable 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 not none , file_name not none: file_loc = "%s:%s" % (file_name, line_no) view.window().open_file(file_loc, sublime.encoded_position) elif file_name 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 key binding command find_in_files_goto
. careful when doing though. ideally, there setting identifies view "find in files" view, use context. i'm not aware of one. of course, if find one, let me know.
edit pulling example key binding main body of answer.
{ "keys": ["enter"], "command": "find_in_files_goto", "context": [{ "key": "selector", "operator": "equal", "operand": "text.find-in-files" }] }
Comments
Post a Comment