6 ms·
I 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
by ectopod 5y ago
I 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>`).