I'm a mac user giving vim a serious try. Most of the GUI editors I'm used to allow me to open a directory as a "project" by executing a command like:
edit ~/www/example.com/
The vim equivalent vim ~/www/example.com/
will show me a list of files in the directory, and I can open them. But it does not set vim's working directory to that path, I have to run :cd .
to set the working directory.
Is there some way, perhaps with a shell script, to open vim and have it's working directory set to a given path?
I'm actually using MacVim, if that makes any difference.
Thanks to @sehe's suggestions, I came up with this. Not sure if it's the best solution, but it seems to work.
Try adding the following to your .vimrc
This will make the directory browsing use a tree style for showing the files (you can expand a directory by putting the cursor on a directory and hitting enter) and make the current working directory also be the one you are browsing.
You might also be interested in the NERDTree plugin that provides a directory browser that is more advanced than the built in one. It has an option
to make the current directory match the root of the displayed tree or
to change the directory whenever you use a command (
:e
or:NERDTree
) to browse a new directory.Braindead:
Less so:
You can always map
:cd %:h
to a convenient key or put in an autocommand (I wouldn't actually recommend the latter, but there is no arguing about taste)Oh and for directories instead of files:
is quite enough
Would this help?
I found it http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file