Fugitive
If your project is under git's control then you use Fugitive.vim.
:echo fugitive#repo().tree()
To edit a file relative to the git root you an use :Gedit
and a /
:
:Gedit /tasks/mytask.js
For more help see:
:h fugitive
:h :Gedit
Projectionist
If you are using Projectionist.vim then you can get the inner most directory by doing the following:
:echo projectionist#path()
Projectionist also provides :Cd
to change the directory from the project root. :ProjectDo {cmd}
will run command, {cmd}
, from the project root.
For more help see:
:h projectionist
:h :Cd
:h :ProjectDo
:h projectionist#path()
Low-tech solution
Forget "auto-cd-ing" to the current file's directory. Just set your current path to your project's root. Use a nice fuzzyfinder like CtrlP to navigate your files.
You can use %:h
to get the current file's directory:
:e %:h
For more help see:
:h 'autochdir'
:h c_%
:h filename-modifiers
Thoughts
Personally I use projectionist for my project needs, however I also keep the current working directory at my project root and never change it. This keeps things simple.
If you do insist on "auto-cd-ing" then I would recommend you look into 'autochdir
. See :h 'autochdir'
.