Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the application URL of a line of code in Visual Studio Code?

Specific lines of code in VS Code can be linked to via an application URL as documented here: https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls

It would be nice to be able right-click on a line of code and get the URL in your clipboard. I can't seem to find how to do this, or if it is even possible to configure VS Code to enable this.

The use case I can think of is pasting the URL into a task manager so when it comes time to work on that line of code, you can easily jump right to it versus trying to remember the code file / LOC.

Is this possible?

like image 778
Bird Law Avatar asked Nov 28 '25 10:11

Bird Law


1 Answers

you can use the following task to print the url to the terminal, you can copy it from there

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "file URL",
      "type": "shell",
      "command": "echo vscode://file${command:extension.commandvariable.file.filePosix}:${lineNumber}",
      "problemMatcher": []
    }
  ]
}

It uses the extension Command Variable to get the correct file separators on Windows (/). It only removes the : of the drive, because you don't want that in Cygwin and MSys.

You can try if this works in opening VSC with the file and line number

      "command": "echo vscode://file${file}:${lineNumber}",
like image 74
rioV8 Avatar answered Nov 30 '25 04:11

rioV8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!