Skip to content

Add rooter_change_directory_for_project_files option #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

barankarakus
Copy link

Purpose:
To replicate autochdir while still computing root directories and storing them as b:rootDir variables.

Purpose: To replicate autochdir while still computing root directories
and storing them as b:rootDir variables.
@airblade
Copy link
Owner

airblade commented Mar 1, 2021

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')

@barankarakus
Copy link
Author

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:rootDir be 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:rootDir variable set by vim-rooter.

There is a seemingly more obvious way to achieve this:

  1. Switch vim-rooter to manual mode, so it doesn't take effect at all.
  2. set autochdir
  3. Use the 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.

@airblade
Copy link
Owner

airblade commented Mar 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants