Visual Studio Code extension - mouse middle click go to definition
Asked Answered
B

2

8

I'm searching for an extension for VS Code something like this:
https://marketplace.visualstudio.com/items?itemName=norachuga.MiddleClickDefinition
It's natively supported in WebStorm, and I want to switch to VSC and it's really annoying.
I didn't find any results on google.
Is any good tutorial or code snipped on how to create one?

Baccarat answered 31/3, 2022 at 14:1 Comment(1)
trying to get this merged in to vscode, give a πŸ‘ if you're interested: github.com/microsoft/vscode/pull/154465 – Obsequent
K
6

Author Credit: https://github.com/danielsamuels

For those of you who are looking for a short term fix for this, I've created an AutoHotkey script which provides middle-click Go To Definition behaviour:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#IfWinActive ahk_exe Code.exe
~MButton::
MouseGetPos, xpos, ypos

if (ypos >= 87) {
    SendInput,{Click}{F12}
}

return

Copy the above contents into a file named vscode-f12-go-to-definition.ahk and run it. You'll see a green H icon in your systray which shows it's running.

Karney answered 31/3, 2022 at 14:8 Comment(3)
Thanks, it's doing the job! – Baccarat
I'm glad to help! – Karney
Thanks! Not sure why this isn't baked in. Guess nobody told the kids at VSCode about the 'ole middle-click "open in new window" convention. – Burnell
S
1

The AutoHotkey v2 translation of https://mcmap.net/q/1342421/-visual-studio-code-extension-mouse-middle-click-go-to-definition by Pedro Barreto is

If WinActive("ahk_exe Code.exe") {
  ~MButton::{
    MouseGetPos &xpos, &ypos
    if (ypos >= 87) {
      SendInput "{Click}{F12}"
    }
  }
}

I have tested on my Visual Code in Windows 10 and it works.


By the way, this end (middle click to go to definition on Visual Studio Code) can be reached at different layers. For example, if your mouse happens to be a Logitech one, its Logitech Options(+) software allows you to do an application-specific mouse button remapping, so that you can simulate Ctrl / Alt + Left Click with your Middle Button when the context is Visual Studio Code. The good part of this approach is that it works across Windows and macOS, i.e. you don't need to write an equivalent script with Karabiner-Elements on mac.

Logitech Options

^ The above screenshot shows simulating an Alt + Left Click with the Middle Button when the active application is Visual Studio Code.

Sarnoff answered 15/4, 2024 at 6:57 Comment(0)

© 2022 - 2025 β€” McMap. All rights reserved.