Basically, I want to tell Vim:
- Open my web browser (for instance, Firefox)
- Open this file (say index.php) in thought this address : http://localhost
- In other words: http://localhost/index.php
PS: Unfortunately I use Windows XP
Basically, I want to tell Vim:
PS: Unfortunately I use Windows XP
If you are running Vim on windows, then this will work:
:! start http://localhost/index.php
This will use the default browser, if you wanted to start a specific browser then you would need the explicit path to the executable (instead of start).
From the Vim help cmd:
:!{cmd}
Execute {cmd} with the shell. See also the 'shell' and 'shelltype' option.
Obviously, if you are on some other system you just need to use the appopriate command to start the browser on that platform.
You'll need to use a method appropriate to your environment to start the web browser, but you already asked a question about that.
So, use :!start cmd /c ...
, !d:\path\to\firefox ...
or whatever. The important bit: you'll want to use "http://localhost/" . expand("%:t")
as the argument passed to the browser. So, do something like
:exec ":!start cmd /c ... " . "http://localhost/" . expand("%:t")
^- leave a trailing space here
EDIT: A Clarification: expand("%:t")
is a Vim script expression which expands to the last component of the current filename. On Windows this means that if the current filename is C:\a complicated path\to\index.html
, expand("%:t")
will return index.html
.
HTH.
On Unix/Linux, use
:! firefox http://localhost/%:p
%:p is the path and filename of the current buffer