vim-rooter icon indicating copy to clipboard operation
vim-rooter copied to clipboard

Add rooter_change_directory_for_project_files option

Open barankarakus opened this issue 4 years ago • 3 comments

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

barankarakus avatar Feb 28 '21 01:02 barankarakus

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

airblade avatar Mar 01 '21 12:03 airblade

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.

barankarakus avatar Mar 06 '21 14:03 barankarakus

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.

airblade avatar Mar 08 '21 12:03 airblade