[ACCEPTED]-How do I open http://localhost in my web browser from Vim?-localhost

Accepted answer
Score: 11

If you are running Vim on windows, then 9 this will work:

:! start http://localhost/index.php

This will use the default 8 browser, if you wanted to start a specific 7 browser then you would need the explicit 6 path to the executable (instead of start).

From 5 the Vim help cmd:


Execute {cmd} with 4 the shell. See also the 'shell' and 'shelltype' option.

Obviously, if 3 you are on some other system you just need 2 to use the appopriate command to start the 1 browser on that platform.

Score: 7

on mac you can

:!open http://localhost/index.php


Score: 2

On Unix/Linux, use

:! firefox http://localhost/%:p

%:p is the path and filename 1 of the current buffer

Score: 1

You'll need to use a method appropriate 8 to your environment to start the web browser, but you already asked a question about that.

So, use 7 :!start cmd /c ..., !d:\path\to\firefox ... or whatever. The important bit: you'll 6 want to use "http://localhost/" . expand("%:t") as the argument passed to the 5 browser. So, do something like

:exec ":!start cmd /c ... " . "http://localhost/" . expand("%:t")
                         ^- leave a trailing space here

EDIT: A Clarification: expand("%:t") is 4 a Vim script expression which expands to 3 the last component of the current filename. On 2 Windows this means that if the current filename 1 is C:\a complicated path\to\index.html, expand("%:t") will return index.html.


More Related questions