Open barankarakus opened 3 years ago
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:
b:rootDir
be the root directory as vim-rooter normally computes it.What's my use case? It's the following:
b:rootDir
variable set by vim-rooter.There is a seemingly more obvious way to achieve this:
set autochdir
FindRootDirectory()
function provided by vim-rooter to access the root directory, rather than b: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.
Purpose: To replicate autochdir while still computing root directories and storing them as b:rootDir variables.