tags:

views:

359

answers:

4

Basically, I want to tell Vim:

  1. Open my web browser (for instance, Firefox)
  2. Open this file (say index.php) in thought this address : http://localhost
  3. In other words: http://localhost/index.php

PS: Unfortunately I use Windows XP

+4  A: 

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.

Cannonade
thanks it worked: start "http://localhost/index.php" "file:///"%:p" (opened my current file in localhost)
janoChen
Glad to hear it :)
Cannonade
+1  A: 

on mac you can

:!open http://localhost/index.php
Peter
+1  A: 

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.

Michał Marczyk
Also, you can use `%:t` in ex commands (the commands which begin with a colon) to signify "the last path component of the file being edited", meaning the basename of the file (like `index.html` in `C:\path\to\index.html`).
Michał Marczyk
A: 

On Unix/Linux, use

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

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

Sam Post
Will this open in the current Firefox instance if one is already open?
technomalogical