For me it's easier to open NetInfo Manager rather that looking for a hidden file. So instead of directly editing your /etc/hosts file you can go to /Applications/Utilities/NetInfo Manager
Once you launch NetInfo Manager you will click on "machines" and then "localhost". Now you want to click on the lock in the bottom left corner so that you can edit the info (must be an admin user). Now duplicate "localhost" and rename the duplicate whatever you want your virtual host to be named. So for instance, you change "localhost copy" to "test.icalshare.com".
Now deselect your new machine by clicking on another one. It will ask you if you really want to make the change. Say yes. There you go.
Another thing. I don't know the wisdom of this but I got it from the apache documentation ( http://httpd.apache.org/docs/vhosts/name-based.html ) and I have had no issues with it. You do not need to specify 127.0.0.1 in your virtual host directives. All you need is "*". For example, the following should work just fine:
You can also add other directives inside your virtual host directive. For example, do you want each of your virtual hosts to have its own php include path? Do you want to add a domain specific alias? If so do this:
php_value include_path "Users/patrick/Documents/Projects/iCalShare/"
Alias /manual/ "/Library/WebServer/Documents/manual/"
Options FollowSymlinks MultiViews
Allow from all
There's plenty of other stuff you can put in there too.
I have also noticed that with these virtual hosts they are case sensitive. Taking the above example, "http://test.icalshare.com" will work, but "http://test.iCalShare.com" will not. Also, if you name you virtual host "php.mac" then "http://php.mac" will work, but "http://www.php.mac" will not. But if you name your virtual host "www.php.mac" then the opposite is true.
As a side note I have gone kinda crazy with virtual hosts since getting os x. I downloaded the PHP documentation Web pages and made a virtual host for that and the same for mysql documentation, phpmyadmin and so on. The convention I have used for tld's is .mac There is no .mac tld so I don't have to worry about it conflicting with real domains. So, if I want my php documentation I go to "http://php.mac"