githubvisual-studio-codeurlcopygitlens

How to copy a URL of code line in VSCode?


It happens often when I work in VSCode and I need to send a code line URL from a repo to a colleague.

There is no native support for this in VSCode. There is a capability that's enabled by Atlassian plugin if you are using Bitbucket. However, I've been looking for a more versatile option.


Solution

  • An answer I found using GitLens:

    Option 1

    1. Install GitLens plugin in VSCode
    2. Open file from a cloned repo then Cmd+Shift+P > type GitLens: Copy
    3. Click on Settings cog and assign key binding (Cmd+C+P is free)
    4. Select a line from code in a cloned repo and use your shortcut to copy URL

    Option 2

    (ref How can I copy the repository URL for a line of code in Visual Studio Code?)

    1. Install GitLens plugin in VSCode
    2. Open file from a cloned repo then Cmd+Shift+P > type GitLens: Copy
    3. Run gitlens.copyRemoteFileUrlToClipboard command.