-
I would like to get the path of an existing neo-tree buffer (i.e., the path of the root node) programatically. Or any node/item the current cursor is pointing to? The path to the root node is main concern; FYI nerd-tree allows to do this like I searched the documentation for "current path" or looked into |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
If you use the 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 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("neo-tree.sources.manager").get_state("filesystem", nil, winid)
print(state.path) |
Beta Was this translation helpful? Give feedback.
-
Thanks! I find the latter one more general approach that subsumes the former one, but the latter doesn't work with the neotree opened in the left panel. More specifically, when neo-tree is on a left sidebar |
Beta Was this translation helpful? Give feedback.
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:
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: