Timothy Basanov
Timothy Basanov

Reputation: 423

Select and 'go to selection' in Sublime

I work with files containing names to other files: stacktraces, documentation, etc. I often need to jump to a specific file/position and to do that I select part of line containing filename, copy it, open 'go to' window and paste it and press enter.

It's working fine, but it pollutes my clipboard.

Are there any solutions to open 'go to' window with text selected already inserted there? I've checked default keymap and found nothing like that.

Upvotes: 2

Views: 378

Answers (1)

skuroda
skuroda

Reputation: 19754

Nothing built in, but you can do it with a plugin.

import sublime_plugin


class GoToFileCommand(sublime_plugin.WindowCommand):
    def run(self):
        window = self.window
        view = window.active_view()
        regions = view.sel()
        if len(regions) == 1:
            if not regions[0].empty():
                window.run_command("show_overlay",
                                   {"overlay": "goto", "show_files": True,
                                   "text": view.substr(regions[0])})
                return
        window.run_command("show_overlay", {
                           "overlay": "goto", "show_files": True})

Then simply rebind ctrl/cmd+p to go_to_file.

Upvotes: 1

Related Questions