Sublime Forum

Simulate click on link behaviour

#1

I am wondering if it is at all possible to copy this IDE functionality in Sublime:
Wherever I see a function or a variable, I can Ctrl+mouse click to move to the definition of the variable or function.

I think this might be perhaps possible positioning the cursor and looking for symbols with the name (similar to Ctrl+R) but I am not sure that Sublime allows also “mouse interactions”

0 Likes

#2

To a limited degree you can change what commands get executed in response to mouse clicks (or wheel scrolls) by using a sublime-mousemap file. This is more limited than a key binding because unlike key bindings, there is no concept of a context you can apply to have different combinations apply at different times.

For example, an appropriately named file (see below) with the following contents will make a control+click execute the goto_definition command. This would do what you want, although you have to do a normal click once to put the cursor into the word before you control+click because the goto_definition command jumps to the definition of the symbol at the cursor position and not the mouse position (though it should be possible to create a plugin that moves the cursor and then executes the command to make things a bit more seamless):

[
    {
        "button": "button1", "count": 1, "modifiers": ["ctrl"],
        "press_command": "goto_definition",
    },
]

The downside of this is that this mouse and key combination together already has a function (add a new cursor at the click location), so by doing this you lose the ability to do that.

If you want to go this way, you want to create a file in your User package (use Preferences > Browse Packages... if you’re not sure where that is) named Default (<PLATFORM>).sublime-mousemap; replace <PLATFORM> with one of Linux, Windows or OSX depending on what platform you’re on.

2 Likes

#3

Many thanks for this information!

I also found a video that seems to be doing what I want, following the same path that you mentioned:

Sublime Text Quick Tip: “Go To Definition” Click Shortcut

0 Likes