You can use the extension Select By
Use the command: selectby.regex
Call by command palette
If you call the command from the Command Palette define the regex in the setting: selectby.regexes
.
In setting.json
add:
"selectby.regexes": {
"selectHTTPs": {
"surround": "https?://[\\w;,/?:@&=+$\\-.!~*'()#]+",
"copyToClipboard": true
}
}
Call with a shortkey
If you call the command with a key binding you can add these arguments to the key binding:
In keybindings.json
add:
{
"key": "ctrl+shift+c",
"when": "editorTextFocus",
"command": "selectby.regex",
"args": {
"surround": "https?://[\\w;,/?:@&=+$\\-.!~*'()#]+",
"copyToClipboard": true
}
}
This uses a very basic HTTP(S) URL regex.
The selection is also copied to the clipboard, no need to use Ctrl+C
Maybe somebody on the internet has written a more elaborate URL regex.
Or you can browse the VSC source to locate the DocumentLinkProvider
that scans for URLs.
Edit
I looked for allowed characters and adjusted the regex. I did not know ()
are allowed.
Characters allowed in a URL
https://www.freecodecamp.org/news/url-encoded-characters-reference