Best way to launch a URL from within VIM

28 views
Skip to first unread message

J S

unread,
Sep 27, 2019, 2:08:27 AM9/27/19
to v...@vim.org
Vim 7.something under (MS) Windows 7.

I want to do the equivalent of:

:!start http://something

But that doesn't work.

This *does* work, but it is ugly (and opens lots of command prompt windows and requries a few "press any key to continues"s. Also, it seems to run CMD twice - i.e., you end up running:

cmd /c cmd /c start ...

:!cmd /c start http://something

I seek a simpler and, ideally, seamless (i.e., no "press any key"s) way.

meine

unread,
Sep 27, 2019, 2:39:01 AM9/27/19
to 'J S' via vim_use, v...@vim.org
On Fri, Sep 27, 2019 at 06:06:10AM +0000, 'J S' via vim_use wrote:
> Vim 7.something under (MS) Windows 7.
>
> I want to do the equivalent of:
>
> :!start http://something

maybe this works when you specify the right program to launch the URL,
eg. with ':!lynx http://something', provided you installed lynx or any
other browser.

vim has a feature that resembles this: by hitting 'gf' over a filename,
vim opens the file under the cursor.

but...

since vim is a _text editor_, browsing websites isn't a feature I
would expect. the better way IMHO is to launch a second terminal or
window and use a browser to open the URL there, copy content there and
get back to vim. certainly there are other environments that provide the
functionality you describe...

//meine

Ken Takata

unread,
Sep 27, 2019, 3:02:55 AM9/27/19
to vim_use
Hi,


2019/9/27 Fri 15:08:27 UTC+9 J S wrote:
Vim 7.something under (MS) Windows 7.

I want to do the equivalent of:

:!start http://something

But that doesn't work.
 
This should work as described in ":help :!start".
Which version of Vim do you use? Win32 version or Cygwin (MSYS2) version?

Regards,
Ken Takata

Christian Brabandt

unread,
Sep 27, 2019, 3:53:01 AM9/27/19
to v...@vim.org
Isn't that what netrw's normal command `gx` provides?

Best,
Christian
--
Das Gesetz macht alle auf erhabene Weise gleich: Es verbietet allen
Menschen unter Brücken zu schlafen und Brot zu stehlen - den Armen
ebenso wie den Reichen.
-- Anatole France

Andy Wokula

unread,
Sep 27, 2019, 10:26:30 AM9/27/19
to vim...@googlegroups.com
Am 27.09.2019 um 08:06 schrieb 'J S' via vim_use:
> Vim 7.something under (MS) Windows 7.
>
> I want to do the equivalent of:
>
> :!start http://something
>
> But that doesn't work.

You need to put a space after `!':
:! start http://something

Non-blocking:
:sil ! start http://something

If you put double quotes around the argument, these will be used for the title:
:sil ! start "http://something"
(opens a console) thus you will want to use
:sil ! start "title" "http://something"
then.

As probably mentioned already, there is more info under
:h :!start

> This *does* work, but it is ugly (and opens lots of command prompt windows and requries a few "press any key to continues"s. Also, it seems to run CMD twice - i.e., you end up running:
>
> cmd /c cmd /c start ...
>
> :!cmd /c start http://something
>
> I seek a simpler and, ideally, seamless (i.e., no "press any key"s) way.

See above :-)

--
Andy

J S

unread,
Sep 27, 2019, 11:53:15 AM9/27/19
to v...@vim.org
>> I seek a simpler and, ideally, seamless (i.e., no "press any key"s) way.


> Isn't that what netrw's normal command `gx` provides?

Bingo! We have a winner! gx does exactly what I want. Thanks.

Note: All other commentary on this thread has been pretty much n/a.

Ni Va

unread,
Sep 27, 2019, 12:00:11 PM9/27/19
to vim_use
I use this :

" Url
function! helper#job_out_cb(self, data) abort "{{{
let g:idx  += 1
let g:data .= string(g:idx)
let g:data .= a:data
let self  = a:self
try
let data  = remove(self.lines, -1) . a:data
catch /.*/
echomsg 'begin'.string(a:data).'end'
endtry
let lines = split(a:data, "\n", 1)
" echomsg string(lines)
call extend(self.lines, lines)
endfunction  "}}}
function! helper#job_exit_cb(self, data) abort   "{{{
let a:self.running = 0
let a:self.error   = a:data != 0
let self   = a:self
let g:self = self
endfunction  "}}}
function! helper#job_cb(fn, job, ch, data)  "{{{
call call(a:fn, [a:job, a:data])
endfunction  "}}}
fun! helper#openurl(...) "{{{
  let cmd_browse = 'rundll32 url.dll,FileProtocolHandler '
  let url_pat = '\w\+:\/\{2}[^ ''()]\+'
  let url     = matchstr(getline(line('.')), url_pat)
  if url != ''
let g:job = job_start(cmd_browse.url, {
\ 'out_cb'  : function('helper#job_cb', ['helper#job_out_cb' , {} ]),
\ 'exit_cb' : function('helper#job_cb', ['helper#job_exit_cb', {} ]),
\ 'out_mode': 'raw'
\})
  else
echomsg 'sorry, no url found on this cursor''line'
  endif
endfunction "}}}

Ruben Safir

unread,
Sep 27, 2019, 12:10:28 PM9/27/19
to vim...@googlegroups.com
cut and past works.

cut and past works...again
cut and past works...again
cut and past works...again
cut and past works...again
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

Ni Va

unread,
Sep 27, 2019, 12:14:44 PM9/27/19
to vim_use
Sorry just call it like this, it works well:
nnoremap wb              :call helper#openurl()<cr>

Ruben Safir

unread,
Sep 27, 2019, 1:54:38 PM9/27/19
to vim...@googlegroups.com
On 9/27/19 12:14 PM, Ni Va wrote:
> Sorry just call it like this, it works well:
> nnoremap wb :call helper#openurl()<cr>
>
>
> Le vendredi 27 septembre 2019 18:00:11 UTC+2, Ni Va a écrit :
>>
>> I use this :
>>

my way is faster

https://krollermuller.nl/vacatures
https://krollermuller.nl/vacatures
https://krollermuller.nl/vacatures
https://krollermuller.nl/vacatures
Reply all
Reply to author
Forward
0 new messages