nvim-tree.lua
nvim-tree.lua copied to clipboard
When I open/close a folder in nvim-tree my view resets and the cursor while being on the same folder now is at the bottom of the screen
It's very annoying and I can't seem to find the reason for it. I've checked my configs and they seem ok.
On the video above. I go to the top of my tree, then I scroll down enough until my general view moves down as well. Then I just press "l" button which just works like that:
function deployHJKLMappings(bufnr)
local api = require("nvim-tree.api")
vim.keymap.set("n", "l", api.node.open.edit, opts("Edit Or Open", bufnr))
end
When I expand or collapse a folder the view just shifts to the top while the cursor being on the bottom :(
Here's my config for nvim-tree:
require "nvimtree/hjkl_style"
local api = require "nvim-tree.api"
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups vim.opt.termguicolors = true
local function on_attach(bufnr)
-- default mappings
api.config.mappings.default_on_attach(bufnr)
-- custom mappings
vim.keymap.set('n', '<C-t>', api.tree.change_root_to_parent,
opts('Up', bufnr))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help', bufnr))
-- hjkl style
deployHJKLMappings(bufnr)
vim.keymap.set('n', '<leader>h', api.tree.toggle_hidden_filter,
opts('Toggle Dotfiles', bufnr))
vim.keymap.set('n', 't', api.node.open.tab, opts('Toggle Dotfiles', bufnr))
end
-- pass to setup along with your other options
require("nvim-tree").setup {
sort_by = "case_sensitive",
view = {width = 30, centralize_selection = false},
renderer = {group_empty = true},
filters = {dotfiles = false},
on_attach = on_attach
}
vim.keymap.set('n', '<space>e', function()
local file_dir = vim.fn.expand('%:p:h')
local cwd = vim.fn.getcwd()
local diplayed_dir
if string.find(file_dir, cwd, 0) ~= nil then
diplayed_dir = cwd
else
diplayed_dir = file_dir
end
api.tree.toggle({path = diplayed_dir, find_file = true})
end)
As you can see I tried using centralize_selection flag and it doesn't help.
General info:
NVIM v0.10.0-dev-43b0e27 Build type: RelWithDebInfo LuaJIT 2.1.1699392533 nvim-tree version HEAD detached at fa00b57
Are all those mappings and settings critical for reproducing this behaviour?
no, I just included them so it would be clear that there is nothing in those mappings that causes this behavior (at least to me it seems like it)
Do you mind providing as minimal reproducer as possible, it will help with the issue. Thanks.
I'm having the same issue. I can reproduce it by running nvim -nu nvt-min.lua
using nvt-min.lua from the "Clean Room" Replication wiki page.
That's true.
-
nvim -nu nvt-min.lua
-
:NvimTreeOpen
-
:unm <buffer> <C-e>
-
<C-e>
couple of times to scroll viewport down -
:lua require('nvim-tree.api').node.open.edit()
Scrolls root node back to top.
I had same issue too for last two weeks. After that I realized it started happening on one of nvim v0.10.x versions. I don't have this issue on stable v0.9.4.
I had same issue too for last two weeks. After that I realized it started happening on one of nvim v0.10.x versions. I don't have this issue on stable v0.9.4.
I was also on v0.10.x and switching to the latest stable version fixes the problem for me as well.
same issue for long time
Looks like the actions here resolves it:
require"nvim-tree".setup{ filters = { dotfiles = true, git_clean = true, no_buffer = false, },
actions = {
change_dir = { enable = false }
},
}
on my machine, this seems intermittent. I have not find specific variable that sometimes making the tree scrolled to bottom.
https://github.com/nvim-tree/nvim-tree.lua/assets/25895873/d0d91b53-007c-49d2-a2de-2c0d95bed886
on the screen recording, I don't use @/pbower 's solution to disable change_dir
action. but disabling change_dir
won't fix for me
Confirming: this is happening on nvim 0.10
If that's the case I'd prefer that we waited some time before investigating this. 0.10 is a very large release, containing many significant change and has had several volatile breaks. Once it's stable we can investigate further.