'neovim/nvim tree doesn't open current directory only the parent directory with git

If I have a parent directory that has git and a bunch of sub directories and I cd into one of the sub directories and launch neovim, neovim/nvim tree would show the parent directory that has a git instead of showing the sub directory i opened it in

I got the neovim config from https://github.com/ChristianChiarulli/nvim. This is what I have in the nvim tree config file:

vim.g.nvim_tree_respect_buf_cwd = 1
vim.g.nvim_tree_icons = {
  default = "",
  symlink = "",
  git = {
    unstaged = "",
    staged = "S",
    unmerged = "",
    renamed = "➜",
    deleted = "",
    untracked = "U",
    ignored = "◌",
  },
  folder = {
    -- arrow_open = " ",
    -- arrow_closed = "",
    default = "",
    open = "",
    empty = "",
    empty_open = "",
    symlink = "",
  },
}

local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
  return
end

local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not config_status_ok then
  return
end

local tree_cb = nvim_tree_config.nvim_tree_callback

nvim_tree.setup {
  disable_netrw = true,
  hijack_netrw = true,
  open_on_setup = false,
  ignore_ft_on_setup = {
    "startify",
    "dashboard",
    "alpha",
  },
  auto_close = true,
  open_on_tab = false,
  hijack_cursor = false,
  update_cwd = true,
  update_to_buf_dir = {
    enable = true,
    auto_open = true,
  },
--   error
--   info
--   question
--   warning
--   lightbulb
  diagnostics = {
    enable = true,
    icons = {
      hint = "",
      info = "",
      warning = "",
      error = "",
    },
  },
  update_focused_file = {
    enable = true,
    update_cwd = true,
    ignore_list = {},
  },
  system_open = {
    cmd = nil,
    args = {},
  },
  filters = {
    dotfiles = false,
    custom = {},
  },
  git = {
    enable = true,
    ignore = true,
    timeout = 500,
  },
  view = {
    width = 30,
    height = 30,
    hide_root_folder = false,
    side = "left",
    auto_resize = true,
    mappings = {
      custom_only = false,
      list = {
        { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
        { key = "h", cb = tree_cb "close_node" },
        { key = "v", cb = tree_cb "vsplit" },
      },
    },
    number = false,
    relativenumber = false,
  },
  trash = {
    cmd = "trash",
    require_confirm = true,
  },
  quit_on_open = 0,
  git_hl = 1,
  disable_window_picker = 0,
  root_folder_modifier = ":t",
  show_icons = {
    git = 1,
    folders = 1,
    files = 1,
    folder_arrows = 1,
    tree_width = 30,
  },
}



Solution 1:[1]

Similar to kyazdani42/nvim-tree.lua issue 1037, you might need to tweak require('nvim-tree').setup, and play with nvim_tree_respect_buf_cwd to see if you can achieve what you want.

Possibly include in that setup:

  update_focused_file = {
                  enable = true,
                  update_cwd = true,
               },

Solution 2:[2]

This behaviour is due to the plugin https://github.com/ahmedkhalf/project.nvim that is installed with the neovim config you are using.

Solution 3:[3]

The configuration contains the https://github.com/ahmedkhalf/project.nvim plugin.

You could either unplug it in the https://github.com/ChristianChiarulli/nvim/blob/master/init.lua

or

add a pattern of your choice e.g. "Makefile" or "main*" to the https://github.com/ChristianChiarulli/nvim/blob/master/lua/user/project.lua

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 hoplageiss
Solution 3 Poltergeist