sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #587: Preview current file in Mozilla through localhost

 tip karma   Rating 3/6, Viewed by 2175 

created:   October 14, 2003 20:30      complexity:   intermediate
author:   Mark Woodward      as of Vim:   5.7

This is something I 'discovered'  whilst trying to preview html or php files in mozilla using the apache server locally.

Put the path as the first line of a file wrapped in the appropriate comments.
eg: php:
<?php // http://localhost/examples/chapter02/vieworders2.php ?>
eg html:
<!-- http://localhost/examples/chapter02/orderform.html -->

Place the following mappings in your .vimrc file
" Typing <S-F12> will open the file in moz through the server.
nmap <S-F12> :sil! !start mozilla "<cfile>"<CR>
imap <S-F12> <esc>:sil! !start mozilla "<cfile>"<CR>i

As I'm working through Wellings PHP and MySQL Web Development I can use my tokens plugin to speed creating the first line as follows:

Add these as the string parts of the array:
(for php)
"phpf <?php // http://localhost/examples/chapter¤«  chapter?   »/¤«  file name  ».php  ?>"
(for html)
"htmlf <!--  http://localhost/examples/chapter¤«  chapter?   »/¤«  file name  ».html  -->"

then on the first line of the file if I type phpf <leader>et I'll only have to enter the chapter number and the filename without the extension. eg    04<cr>  orders<cr>
This will insert:
<?php // http://localhost/examples/chapter04/orders.php ?>

Place the cursor anywhere on the file path, <S-F12> and the file will load (through apache) in moz.

Hope someone finds this useful,
Mark

 rate this tip  Life Changing Helpful Unfulfilling 

<<Smarter Pasting | How to sort using visual blocks >>

Additional Notes

markwoodwardATbigpond.com, October 14, 2003 20:38
I'd be interested if there's a way to open in a new tab in moz rather than a new window? Or even open in the current window (replacing the old page). Does anyone have any suggestions?

--
Mark
[email protected], October 18, 2003 4:40
Try something like this:

mozilla -remote 'openURL(https://www.vim8.org, new-tab)'

HTH

André
[email protected], October 30, 2003 12:49
A related piece of info for Windows:

        start filename.ext

(in the shell) "opens" the named file with its default action. This means, for instance, that

        :w | ! start %

(in Vim with the cursor on an html file) will save the current file, then open it in your default browser. On my system, it opens a new Dos Box and a new Netscape 7 window. The Dos box must be closed by <Enter> to return to Vim. You may leave the browser window open if you like (for instance, after you next make some changes and save the file, click "Reload" or press Ctrl-R in the browser to see the new version).

Beware: The space between ! and start is necessary (if I leave it out, I get Vimm error E371).

Regards,
Tony.
[email protected], December 21, 2003 13:44
I don't know what "S-" means in "<S-F12>" - does it mean Shift-F12 possibly?
ste[delete]pta[metoo]n at hot[andme]mai[last]ldot com, January 8, 2004 20:19
Yes, S is shift.
M is alt
C is ctrl

Examples:

<F9>    : just press F9
<M-F9>  : press alt and F9
<C-F9>  : press ctrl and F9
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo