Closed Iron-E closed 1 year ago
Hey @Iron-E, this is my current nvim-tree.lua
config:
local status_ok, nvimtree = pcall(require, 'nvim-tree')
if not status_ok then
print('nvim-tree is not working. Skipping...')
return
end
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
local options = {
filters = {
dotfiles = false,
},
disable_netrw = true,
hijack_netrw = true,
hijack_cursor = true,
hijack_unnamed_buffer_when_opening = false,
sync_root_with_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
},
}
-- setup with some options
nvimtree.setup(options)
-- auto open nvim-tree when open neovim
local function open_nvim_tree(data)
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- only files please
if not real_file and not no_name then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
vim.api.nvim_create_autocmd({ "VimEnter" }, {
callback = open_nvim_tree
})
-- auto close nvim-tree
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NvimTreeClose", {clear = true}),
pattern = "NvimTree_*",
callback = function()
local layout = vim.api.nvim_call_function("winlayout", {})
if layout[1] == "leaf" and vim.api.nvim_buf_get_option(vim.api.nvim_win_get_buf(layout[2]), "filetype") == "NvimTree" and layout[3] == nil then vim.cmd("confirm quit") end
end
})
I'm gonna take a look at this next.
@bavo96 I tried your config but couldn't reproduce. Two things we can try:
vim.g.barbar_auto_setup = false
(see the README). It's a recent feature that may help in this case.require'barbar'.setup
is called before require'nvim-tree'.setup
, and before the tree opens for the first time.If you try all that and the problem is still happening, see if you can't get it to reproduce with nvim --clean
:
nvim --clean
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/barbar.nvim'
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-tree.lua'
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-web-devicons'
--cmd 'lua require"bufferline".setup{ OPTIONS_HERE }'
-u minimal.lua
You will have to adjust the rtp
s, and fill your minimal.lua
with any other commands.
Hey @Iron-E, been busy these days and now I have time to go back with this. I have tried the two suggestions above, it seems to work now but there's a small issue. When I first open neovim with a default buffer, the sidebar haven't appeared yet and only when I open a file, the sidebar appears, as shown in the below clip:
I have also tried the nvim-clean
and the result is the same:
And this is my setup for nvim-clean
:
nvim --clean \
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/barbar.nvim' \
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-tree.lua' \
--cmd 'set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-web-devicons' \
--cmd 'lua require"bufferline".setup{
-- Enable/disable animations
animation = true,
-- Icons in barbar
icons = {
-- Configure the base icons on the bufferline.
buffer_index = true, -- Index according to visual index on the screen not the background number of buffer
},
-- Set the filetypes which barbar will offset itself for
sidebar_filetypes = {
NvimTree = true,
},
}' \
--cmd 'lua require"nvim-tree".setup{
filters = {
dotfiles = false,
},
disable_netrw = true,
hijack_netrw = true,
hijack_cursor = true,
hijack_unnamed_buffer_when_opening = false,
sync_root_with_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
},
}' \
-u minimal.lua
vim.g.barbar_auto_setup = false
-- auto open nvim-tree when open neovim
local function open_nvim_tree(data)
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- only files please
if not real_file and not no_name then
return
end
-- open the tree but dont focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
vim.api.nvim_create_autocmd(
{ "VimEnter" },
{ callback = open_nvim_tree })
I can reproduce with that, thank you!
Nvim-tree doesn't emit BufWinEnter
on start. I'll have to report it upstream.
For now, you can add:
vim.api.nvim_exec_autocmds('BufWinEnter', {buffer = vim.fn.bufnr('#')})
after toggling the tree to emit it yourself.
Many thanks for your effort :D I don't know if I'm doing right but after adding the line to nvim-tree.lua, I got this error:
This is my current setting for nvim-tree config:
local status_ok, nvimtree = pcall(require, 'nvim-tree')
if not status_ok then
print('nvim-tree is not working. Skipping...')
return
end
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
local options = {
filters = {
dotfiles = false,
},
disable_netrw = true,
hijack_netrw = true,
hijack_cursor = true,
hijack_unnamed_buffer_when_opening = false,
sync_root_with_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
},
}
-- setup with some options
nvimtree.setup(options)
-- auto open nvim-tree when open neovim
local function open_nvim_tree(data)
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- only files please
if not real_file and not no_name then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
vim.api.nvim_create_autocmd({ "VimEnter" }, {
callback = open_nvim_tree
})
-- Emit BufWinEnter
vim.api.nvim_exec_autocmds('BufWinEnter', {buffer = vim.fn.bufnr('#')})
-- auto close nvim-tree
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NvimTreeClose", { clear = true }),
pattern = "NvimTree_*",
callback = function()
local layout = vim.api.nvim_call_function("winlayout", {})
if layout[1] == "leaf" and vim.api.nvim_buf_get_option(vim.api.nvim_win_get_buf(layout[2]), "filetype") == "NvimTree" and layout[3] == nil then
vim.cmd("confirm quit") end
end
})
Sorry for any confusion. This will work:
require'nvim-tree'.setup {}
-- auto open nvim-tree when open neovim
local function open_nvim_tree(data)
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == '' and vim.bo[data.buf].buftype == ''
-- only files please
if not real_file and not no_name then
return
end
-- open the tree but dont focus it
require('nvim-tree.api').tree.toggle({ focus = false })
vim.api.nvim_exec_autocmds('BufWinEnter', {buffer = require('nvim-tree.view').get_bufnr()})
end
vim.api.nvim_create_autocmd({'VimEnter'}, { callback = open_nvim_tree })
Many thanks @Iron-E it works now, you rock <3 Wish you all the best :D
Apparently this is a bug upstream in Neovim. It will be necessary to use that workaround until it is fixed.
See:
cc @bavo96; what was your NvimTree config?