Sublime Forum

Key binding to trigger on_hover

#1

Is there any command you can bind a key to that will have the effect of hovering the mouse over the caret?

I use plugins that show documentation/references/errors when you hover over text. I want a way to show this stuff without using the mouse. I can’t find documentation about this anywhere. Is it possible? If not, why?

0 Likes

#2

You can create a TextCommand which reads the current caret position and displays the popup. This is what GitGutter does. The popup is primarily created by an TextCommand which can be bound to a key. The EventListener just calls that text command in the on_hover handler.

0 Likes

#3

for a plugin agnostic approach, where the plugin developer hasn’t exposed a command related to the hover functionality, you could execute something like the following from a keybinding:

import sublime, sublime_plugin
sublime_plugin.on_hover(view.id(), view.sel()[0].begin(), sublime.HOVER_TEXT)
2 Likes

#4

This works perfectly; thanks!

Although I still feel like this would be a good command to have built in to ST or at least Vintageous

0 Likes

#5

This is a hack, that will trigger the on_hover for all plugins called by a key combination or the logic of any plugin. I tend to call it a bad hack which I wouldn’t prefer or recommend.

The mentioned function is part of the event ecosystem and should not be used by plugins directly!

0 Likes