collapse other directories, but only open the directory of current buffer. #1929
-
so when I jump between buffers, I only want the current buffer's nested directory to open and display in sidebar. the only solution I can think of is run :NvimTreeCollapse first, then open NvimTree. is there other better solution? without typing command. |
Beta Was this translation helpful? Give feedback.
Answered by
alex-courtis
Jan 21, 2023
Replies: 1 comment 2 replies
-
You could use a little bit of automation like this: local nt_api = require("nvim-tree.api")
local function collapse_and_find(data)
nt_api.tree.collapse_all()
nt_api.tree.find_file(data.file)
end
vim.api.nvim_create_autocmd({ "BufEnter" }, { callback = collapse_and_find }) You could add some filtering of filetypes / buffer types etc. however I'll leave that as an exercise for the reader. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
zztczcx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could use a little bit of automation like this:
You could add some filtering of filetypes / buffer types etc. however I'll leave that as an exercise for the reader.