locate: use context to locate type or value appropriatly
Handles the last point of #308

Also, minor code cleanup.
vim: add a dump_to_file function