nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.18k stars 611 forks source link

Opening folder with `nvim folder/` doesn't show nvim-tree anymore #1981

Closed pablopunk closed 1 year ago

pablopunk commented 1 year ago

Description

Sorry if this was asked before (couldn't find it).

Basically when opening a folder with nvim folder it used to show the nvim-tree view with all the contents of the directory. Now it doesn't do it anymore until I force it to reload the buffer (e.g e!).

asciicast

I can reproduce it with the minimal config just adding vim.g.loaded_netrwPlugin = 1 (see below)

Neovim version

NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compilado por brew@HMBRW-A-001-M1-004.local

Features: +acl +iconv +tui
See ":help feature-compile"

     archivo "vimrc" del sistema: "$VIM/sysinit.vim"
            predefinido para $VIM: "
/opt/homebrew/Cellar/neovim/0.8.0/share/nvim"

Run :checkhealth for more info

Operating system and version

macOS 13.1

nvim-tree version

02fdc26

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- I added only this line
vim.g.loaded_netrwPlugin = 1

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {}
end

Steps to reproduce

With the nvt-min.lua file loaded, I only needed to add vim.g.loaded_netrwPlugin = 1 to that config to reproduce the issue:

nvim -nu /path/to/nvt-min.lua .

asciicast

Expected behavior

Show nvim-tree with directory contents

Actual behavior

It doesn't show nvim-tree

pablopunk commented 1 year ago

Silly me, I've just found Open at startup and saw the new changes. I fixed it by adding this to my config

local function open_nvim_tree()
  require("nvim-tree.api").tree.open()
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })

EDIT: Although my desired behavior looks more like:

local function open_nvim_tree(data)
  local is_real_file = vim.fn.filereadable(data.file) == 1
  local is_no_name_file = data.file == "" and vim.bo[data.buf].buftype == ""
  local is_a_directory = vim.fn.isdirectory(data.file) == 1

  if is_a_directory then
    vim.cmd.cd(data.file)
    require("nvim-tree.api").tree.open()
    return
  end

  if is_real_file or is_no_name_file then
    require("nvim-tree.api").tree.toggle { focus = false, find_file = true }
    return
  end
end