-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sidebar_filetypes
with NvimTree
doesn't work on startup
#421
Comments
Hey @Iron-E, this is my current 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:
If you try all that and the problem is still happening, see if you can't get it to reproduce with 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 |
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: barbar-2023-04-10_23.01.52.mp4I have also tried the barbar2-2023-04-10_23.03.23.mp4And this is my setup for bashnvim --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 minimal.luavim.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 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?
The text was updated successfully, but these errors were encountered: