4

My projects are in:

/home/user/projectA
/home/user/projectB

However, at times I hit CtrlP and I haven't opened a file in a particular project, so my working directory is /home/user. CtrlP starts indexing this whole directory, which is huge and takes a whole lot of time every time I accidentally hit CtrlP. How can I avoid this? I have seen that I can exclude files and directories using Vim's wildignore and CtrlP's own g:ctrlp_custom_ignore, but that doesn't work as I can't ignore a parent directory and still search in a child directory. Any ideas?

Alternatively, I would also be happy with Vim automatically making /home/user/projectA the default working directory, just to avoid ever having /home/user as the working directory.

1 Answer 1

4

2 ways of doing that:

  • On your terminal, move to your project directory then execute vim.
  • Manually specify the working directory into vim using :cd command (You can check the current working directory with :pwd).

Extra

CtrlP

If you're using ag with ctrlp, you can create a .agignore file into your working directory, and specify there what ctrlp should ignore and not index.

A little but useful vim command

In my vimrc I have the following command:

command! Dir :cd %:p:h

So with Dir I can set the current vim working directory to the current file's path, its useful sometimes.


EDIT:

You can use vim autocommands (h autocmd) to automate the process.

Example if you want to make /path/project be your cwd in each vim start, add then to your vimrc:

autocmd VimEnter * :cd /path/project

The event VimEnter is quite understandable (h autocmd-events).

2
  • Thanks but it seems that this won't solve my issues. Is there a way of forcing my initial working directory (upon starting vim) to be a particular directory? Independently from how I start it. Your tips are useful but my goal is not having to go to a particular directory in the terminal or change the working directory manually... the idea is that this is done by default. And although I am using ag with ctrlp, the problem is if I exclude the parent directory, the child directories won't be indexed either...
    – user
    Oct 14, 2015 at 8:20
  • You can use vim autocommands for that (I've edited my post). Oct 14, 2015 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.