Possible Duplicate:
set .vim home directory to something specific
There is already a question about setting a working directory: How to set working/current directory in Vim? However my problem is a little different, I have several thousands files (several different projects) in a folder. Whenever I start Vim (MacVim), the cwd is by default set to home dir. Thus when I'm using plugins like ack.vim they by default are searching in my home dir which is useless. I just want to set it to my /home/user/Code folder (which has all my snippets, projects,etc..)
Is there any settings which sets the cwd to a certain directory? Or any workarounds (like executing :cd /home/user/Code
for every startup in Vim?
You could just hard-code the current working directory via
:cd /home/user/Code
in your ~/.vimrc
. But that leads to a strange setup whenever you edit files elsewhere. (And even if you're mainly editing inside your Code
directory, there is the occasional edit of ~/.bashrc
, or a config setting in /etc/...
, and so on.
What I do is put the :cd
into a local vimrc inside the Code
directory. (I use the localrc.vim plugin; there are others.) Then, the directory is changed only when I actually edit any file withing that directory tree.
You can
:se autochdir
This will automatically change to the directory containing the opened file.
Or
:cd %:h
to change to the directory containing the currently opened file now
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With