neo-tree.nvim icon indicating copy to clipboard operation
neo-tree.nvim copied to clipboard

Working directory changes when sidebar is focused

Open showermat opened this issue 2 years ago • 7 comments

Hi, thanks for this exciting plugin!

I'm running into weird behavior that's so obvious I'm sure I'm doing something wrong. With follow_current_file = true, the view in the Neo-tree sidebar follows the currently edited file as long as my cursor stays in the file window. Great! But the moment I switch focus to the Neo-tree window, Neo-tree jumps back to whatever directory it was in when I opened the sidebar. If I move focus back out of the Neo-tree window, it jumps back to the directory containing the file I'm editing.

It feels like Neo-tree is displaying the working directory of the focused window but not changing its own window's working directory to match. I played with the values of bind_to_cwd and cwd_target, but nothing seems to help. I do have autochdir set, but disabling it seems to break file following entirely. Here's a minimal config that reproduces the problem for me:

call plug#begin(stdpath("data") . "/plugged")
Plug 'nvim-lua/plenary.nvim'
Plug 'MunifTanjim/nui.nvim'
Plug 'nvim-neo-tree/neo-tree.nvim', {'branch': 'v2.x'}
call plug#end()

set autochdir

lua << !
require("neo-tree").setup({
	filesystem = { follow_current_file = true },
})
!

Does anything stand out to you that could be causing this? Thanks!

showermat avatar Jan 23 '23 00:01 showermat

Yes, this stands out:

set autochdir

That is causing your problem. If you use that, you'll want to disable neo-tree's bind_to_cwd option.

cseickel avatar Jan 24 '23 13:01 cseickel

Ah, okay. That wasn't fixing the problem for me, so I read the code -- which is probably what I should have done from the start. I found this snippet: if not is_in_path then return false end.

So it looks like Neo-tree is designed to bail out and not follow if the file is outside the current root. Is there a way to get "universal" following -- something like the pseudocode, if is_in_path then [current behavior] else cwd(dirname(file.path)) end?

showermat avatar Jan 25 '23 01:01 showermat

@showermat I have tested with follow_current_file = true and :set autochdir, which seems to work well. Is this the desired behavior for you?

nhat-vo avatar Feb 21 '23 15:02 nhat-vo

In my setup, that doesn't work as I expect. With :set autochdir, follow_current_file = true, and bind_to_cwd = false as prescribed above, the view in Neo-tree does not change at all when I open a new file unless that file is already below the current top-level directory open in Neo-tree. As I mentioned in my previous comment, I think this is due to a mismatch in expectations of in what circumstances Neo-tree should follow the file.

showermat avatar Feb 23 '23 03:02 showermat

Ah ok I see. I will have a look at how to implement this.

nhat-vo avatar Feb 24 '23 09:02 nhat-vo

Hey @nhat-vo, is there any update on the issue? 🙂

burningalchemist avatar Jan 12 '24 11:01 burningalchemist