3 ms·
> 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
by 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>`).