4 ms·
I fixed my editor so that it recognizes URLs, and underlines them. Clicking on one brings up a browser on that site. I should have done that 20 years ago. No s
by WalterBright 5y ago
I fixed my editor so that it recognizes URLs, and underlines them. Clicking on one brings up a browser on that site. I should have done that 20 years ago.
No special syntax is required. It just works. I've since been adding URLs in comments all over my code, for references. It's marvelous.
It could be extended to recognize filename.jpg and filename.mp3 to display or play those files, too. Again with no special syntax whatsoever. It just works.
https://github.com/DigitalMars/med https://github.com/DigitalMars/med
- ectopod 5y agoI wish vim could do this. Or maybe it can and I don't know how. Everyone suggests using "gx" but this is for opening local files in a viewer. If you do gx on a url it downloads the referent, and then tries to open the result using the local filename. If the extension is ".html" this fails fairly miserably because all the css, images, etc. are missing. If the page doesn't have an extension it fails entirely. I look forward to being corrected!
- alpaca128 5y ago> I wish vim could do this. You can make it do that with a keybinding and a little vimscript function. Vim can run shell commands, so all it really needs to do is check if the text under the cursor is a URL, and if it is call a browser on it. Something like this (note I'm not exactly a vimscript master): function! OpenUrl() let pattern = 'http[^)\]"\n \t<>]\+' let line_text = getline('.') let matched = matchstr(line_text, pattern) if strlen(matched) > 0 exe "norm! :!firefox ".matched."\n" endif endfunction nmap <CR> :call OpenUrl()<CR> This calls the function when you hit Enter in normal mode (the `<CR>`).