Nvim-tree.lua: Not opening in repository root

Created on 18 Jan 2021  Â·  8Comments  Â·  Source: kyazdani42/nvim-tree.lua

Have noticed that tree does not open in repository's root in case such as:

  1. ~/ $ nvim
    a. open file with Startify that is part of git repository
    b. invoke :NvimTreeFindFile — tree is opened with root still being ~ (I use vim vim-rooter to change nvim's pwd)
    c. close tree buffer with q (or any other way)
    d. invoke :NvimTreeFindFile again — tree correctly opened in buffer's repository root directory

1.a correctly changes nvim's directory; :pwd return repository's root directory for opened file so vim-rooter does its job.

Other than that - the best tree plugin there is! Thanks!

bug

Most helpful comment

I have noticed while making your plugin lazy load that it would not work at all and had to put

vim.cmd "doautocmd NvimTree BufEnter *"

into packer's config function for nvim-tree. With that in place I had no problem with tree opening in repository root. Perhaps that info will help you somewhat.

Thanks for all your work on that plugin and treesitter!

All 8 comments

thanks :)
well yes i've disabled git-rooter because it conflicted with this and other plugins too, but i know cwd startup is a bit wonky, a refactoring is definitely needed here.

I have noticed while making your plugin lazy load that it would not work at all and had to put

vim.cmd "doautocmd NvimTree BufEnter *"

into packer's config function for nvim-tree. With that in place I had no problem with tree opening in repository root. Perhaps that info will help you somewhat.

Thanks for all your work on that plugin and treesitter!

you're welcome :) well lazy loading is not working because of the way i setup nvim tree. I have to rework the setup tu be more lua like which would probably allow lazy loading

With what you are doing in plugin/ I don't really need to lazy load it at all, just tried ink the past and came over this 'accidental fix' for root issue.

:NvimTreeToggle still opens in my home folder the first time; I have to close and reopen the file viewer to make it open the directory the file is at. (This happens when I'm trying to open a session from Startify, with buffers inside ~/.config/nvim.)

@cloggier I've tried your workaround, but I get the following error:

Error running config for nvim-tree.lua
Error in packer_compiled: Vim(lua):E5108: Error executing lua [string ":lua"]:52: [string "..."]:0: Vim(doautocmd):E216: No such group or event: NvimTree BufEnter *
Please check your config for correctness

Here's how I've set it up using Packer:

use {
  'kyazdani42/nvim-tree.lua',
  requires = {'kyazdani42/nvim-web-devicons', opt = true},
  config = function()
    vim.cmd([[doautocmd NvimTree BufEnter *]])
  end
}

Is this how you did it, or do I need to change anything?

use {

'kyazdani42/nvim-tree.lua',

requires = {'kyazdani42/nvim-web-devicons', opt = true},

config = function()

vim.cmd([[doautocmd NvimTree BufEnter *]])

end

}

You are not lazy loading the plug-in. Try adding keys or cmd keys to packer (if I remember names well).

OK, I've tried the following:

use {
  'kyazdani42/nvim-tree.lua',
  requires = {'kyazdani42/nvim-web-devicons', opt = true},
  cmd = 'NvimTreeToggle',
  config = function()
    vim.cmd([[doautocmd NvimTree BufEnter *]])
  end
}

After running :PackerCompile and restarting Neovim, I no longer receive any errors, but running :NvimTreeToggle has the same results as before.

Edit: It looks like I also needed to run :PackerSync so that nvim-tree.lua can actually be lazy-loaded. So, after that, the sidebar of nvim-tree is always empty.

Ah, sorry then, maybe something has changed internally since I had it working. No lazy loading it any more. Just waiting for git root bug to be fixed. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ziulev picture ziulev  Â·  8Comments

GustavoPrietoP picture GustavoPrietoP  Â·  6Comments

greister picture greister  Â·  8Comments

seblj picture seblj  Â·  6Comments

ecosse3 picture ecosse3  Â·  5Comments