Wednesday, May 25, 2011

Previewing files in localhost on Mac

Hi there:
I use Vim to write PHP, and am looking for a way to quickly preview
PHP files through localhost. After some brief research (http://
vim.wikia.com/wiki/VimTip1015), I came up with the following key remap
solution for Mac using xampp:

map <F1> :w<CR>:!open -a Google\ Chrome `echo http://localhost/${PWD\#*/*/*/*/*/}/%`<CR>

This trick works, but only if I'm editing a file which is located
somewhere in my $PWD. In other words, if % in the register is relative
(index.php or mywebsite/index.php), then it appends smoothly onto the
truncated directory structure. However, if my present file is outside
the $PWD and % is absolute (/Applications/XAMPP/xamppfiles/htdocs/
mywebsite/index.php), then this trick fails, and I get a 404 error.

I can probably live with this flaw and work around it, but I figured
some of you ninjas out there might have a superior, more comprehensive
solution.

Also, is there someone out there willing to break down this piece of
code for me: ${PWD\#*/*/*/*/*/}. It manages to strip directories from
the left of the string, but how? So far I looked here but it didn't
shed any light: http://www.gnu.org/software/bash/manual/bashref.html#Word-Splitting

Thank you very much. -JP


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment