Sublime Forum

Open file from find results keyboard shortcut

#1

I originally posted this question on superuser, but got no response so thought I would try here. thanks in advance for any advice/suggestions.

In the “Find in Files” results, a box is drawn around wherever your search term appears. Double clicking within that box opens the file and focuses your cursor on that line.

Is there any way to achieve this using only your keyboard?

I understand you could use cmd+p to open file then ctrl+g to goto line, but I was hoping there was a single combo you could use to go directly to the result, like the double click offers.

superuser.com/questions/511658/s … d-shortcut

0 Likes

#2

I wrote a simple plugin that will emulate a double click at the caret position(s):

import sublime
import sublime_plugin


class DoubleClickAtCaretCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        view = self.view
        window_offset = view.window_to_layout((0,0))
        vectors = []
        for sel in view.sel():
            vector = view.text_to_layout(sel.begin())
            vectors.append((vector[0] - window_offset[0], vector[1] - window_offset[1]))
        for idx, vector in enumerate(vectors):
            view.run_command('drag_select', { 'event': { 'button': 1, 'count': 2, 'x': vector[0], 'y': vector[1] }, 'by': 'words', 'additive': idx > 0 or kwargs.get('additive', False) })

This works in the Find Results to go to the result line where the caret is. But it still doesn’t go to the column where you double clicked.

See also Find Results double-click for an easier solution using the built in goto next/prev find result functionality.

Also related: Find results: How to go to certain result with keyboard?

1 Like

Open find in “find” hotkey
#3

now that Dev Build 3142 has a text_to_window API, we can simplify the plugin in my previous post to:

import sublime
import sublime_plugin


class DoubleClickAtCaretCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        view = self.view
        vectors = [view.text_to_window(sel.begin()) for sel in view.sel()]
        for idx, vector in enumerate(vectors):
            view.run_command('drag_select', { 'event': { 'button': 1, 'count': 2, 'x': vector[0], 'y': vector[1] }, 'by': 'words', 'additive': idx > 0 or kwargs.get('additive', False) })
2 Likes

#4

How can I integrate this command in Sublime Text?

Where do I save it?

0 Likes

#5

into Packages/User - just use the Tools - Developer - New Plugin… menu item and replace the stub and it will suggest the correct folder to save in automatically

0 Likes

#6

I did that and saved it as click-at-caret.py inside my Sublime User folder.

I restarted Sublime and I still have to double click inside cmd+shift+f global search window.

Perhaps I have to add something else?

0 Likes

#7

a keybinding to execute the double_click_at_caret command probably

0 Likes

#8

I tried that and nothing happens.

I tried to single click on the results in ‘Search All’ window:

And I still have to double click to go to the result. I also want to be able to press Enter once and pick the result. Right now that too doesn’t work. :disappointed:

0 Likes

#9

The command name in your binding should be double_click_at_caret as @kingkeith mentioned above, not DoubleClickAtCaretCommand; the command name is a version of the name of the command class that defines it.

1 Like

#10

Thank you @OdatNurd. It works now.

Do you know how I can make it so that I only have to left click once on the results in that window to open it?

0 Likes

#11

I’ve been using Kingkeith’s double-click-at-caret plugin for years now (many thanks for that!) but a recent build of sublime text has broken the functionality. It could also just be an issue on M1 Macs, I haven’t tested on Linux or PC.

An alternative I’ve found which works as needed is to just use the built in prev_result command. This is the keybinding I use:

{ "keys": ["super+t"], "command": "prev_result" }

Now when I have my caret on a search result line and press cmd + t it does the same thing as if I double clicked it.

0 Likes

#12

There’s a recent command announced on discord called current_result.

Here’s my custom keybindings. The default keybindings are on the left.

0 Likes