Skip to content

How to get the current path of a neo-tree buffer? #319

Answered by cseickel
wookayin asked this question in Q&A
Discussion options

You must be logged in to vote

If you use the bind_to_cwd option, which is true by default, then a sidebar tree's root will be the same as the tab working directory. A tree opened in a window with the "current" position will use the local working directory of that window.

Alternatively, you can read the state of a tree with:

local state = require("neo-tree.sources.manager").get_state("filesystem")
print(state.path)

That will give you the state of the "filesystem" sidebar in the current tab. The parameters to the get_state function are: source_name, tabnr, winid

If you want to get the state for a particular window that is not a sidebar, pass the window id:

local winid = vim.api.nvim_get_current_win()
local state = require(

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
9 replies
@ryanmsnyder
Comment options

@cseickel
Comment options

@ryanmsnyder
Comment options

@cseickel
Comment options

@ryanmsnyder
Comment options

Answer selected by wookayin
Comment options

You must be logged in to vote
3 replies
@cseickel
Comment options

@wookayin
Comment options

@cseickel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
4 participants
Converted from issue

This discussion was converted from issue #309 on April 24, 2022 14:11.