Add rooter_change_directory_for_project_files option
Purpose: To replicate autochdir while still computing root directories and storing them as b:rootDir variables.
In that case wouldn't it be simpler to add two lines to your vimrc instead of using this plugin?
set autochdir
autocmd BufEnter * let b:rootDir = expand('<afile>:p:h')
Thanks for getting back to me.
I don't want to set b:rootDir to the directory of the buffer/file being edited:
- I want my current directory to be the directory that the buffer I'm currently editing is in.
- But I also want
b:rootDirbe the root directory as vim-rooter normally computes it.
What's my use case? It's the following:
- I want my current directory to be the directory that the buffer I'm currently editing is in.
- But still be able to, for example, search for files from the project root - which I can do so thanks to the
b:rootDirvariable set by vim-rooter.
There is a seemingly more obvious way to achieve this:
- Switch vim-rooter to manual mode, so it doesn't take effect at all.
set autochdir- Use the
FindRootDirectory()function provided by vim-rooter to access the root directory, rather thanb:rootDir
I've found that the problem with this lies in Step 2. autochdir behaves strangely. For example, I defined a command that would search for files from the project root, but every time I invoke that command, autochdir causes me to cd into the project root. Now, I haven't sat down to debug what part of the command might be causing autochdir to behave this way - I adapted the :Files command from the fzf.vim plug-in - but I do get the impression that autochdir should be avoided whenever possible. For one, the vim docs provide a warning that 'some plugins may not work' if autochdir is set.
I think it's worth persevering with your approach a bit longer. I'm not sure why autochdir would be making your command change directory to the project root but presumably it's solvable.
You could try defining a command which turns off autochdir, runs vim-rooter manually, does your actual file-finding, then turns autochdir back on.