Sublime Forum

Go To Definition within active file

#1

I can’t seem to figure out how to Go To Definition (F12) only within the active file. What I’ve been doing is using Go To Symbol (ctrl+r), then typing the symbol I’m looking for. It would be nice if something like ctrl+F12 would Go To Definition in the currently active file rather than pulling up the list of files with possible matches. Or is this already possible and I’m just not seeing it?

** EDIT **

Here is a python plug-in yielding this functionality:

[code]import sublime, sublime_plugin

class goto_definition_in_active_fileCommand(sublime_plugin.TextCommand):
def run(self, edit):
selections = self.view.sel()

    if len(selections) > 1:
        return
        
    selection = selections[0]
    word = None
    
    if selection.empty():
        word = self.view.substr(self.view.word(selection))
    else:
        word = self.view.substr(selection)
    
    self.view.window().run_command("show_overlay", {"overlay": "goto", "show_files": False, "text": "@" + word})
    self.view.window().run_command("hide_overlay")
    
    self.view.window().run_command("move_to", {"to": "bol", "extend": False})
    return[/code]

I have it bound to F12, and then I changed the default F12 binding to ctrl+F12:

{ "keys": "ctrl+f12"], "command": "goto_definition"}, { "keys": "f12"], "command": "goto_definition_in_active_file"}

0 Likes