I had the same problem, so I wrote my own function for it. (Thanks to the guy below who had a way to do it without having to use the registry. I modified my own with this.)
The strategy is to store the url under the Vim-cursor to a variable
let url = expand('<cWORD>')
and then use bash to open firefox with the url as argument:
call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
The &
is used to open firefox in the background, and the \<CR>\<ESC>
is to enter the command and escape the message box that it prompts.
We put this into a function that we call OpenURL()
and then remap gxgx
to run that function.
nnoremap gx :call OpenURL()<CR>
The <CR>
is again to actually execute the command in Vim.
In total it looks like this:
function! OpenURL()
let url = expand('<cWORD>')
call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction
nnoremap gx :call OpenURL()<CR>