Skip to content

collapse other directories, but only open the directory of current buffer. #1929

Answered by alex-courtis
zztczcx asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@zztczcx
Comment options

@alex-courtis
Comment options

Answer selected by zztczcx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants