Replies: 4 comments
-
Alternatives:
I'm leaning towards a recipe for 1. |
Beta Was this translation helpful? Give feedback.
-
Have a play with this hacky mapping in your on_attach: vim.keymap.set("n", "x", function()
local node = api.tree.get_node_under_cursor()
local cmd = { "git", "-C", vim.fs.dirname(node.absolute_path), "rev-parse", "--show-toplevel" }
-- strip trailing newline
local toplevel = vim.fn.system(cmd):sub(0, -2)
local stat, _ = vim.loop.fs_stat(toplevel)
if stat and stat.type == "directory" then
-- change to toplevel
api.tree.change_root(toplevel)
else
-- failure message
print(toplevel)
end
end, opts("CD git toplevel")) |
Beta Was this translation helpful? Give feedback.
-
Hi @alex-courtis I tried your code and I do see that the |
Beta Was this translation helpful? Give feedback.
-
What happens when you execute the mapping? Can you print
Baby steps. Let's get this going with a mapping then we can automate. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is this a question?
No
Can this functionality be implemented utilising API?
Not sure
Is your feature request related to a problem? Please describe.
No
Describe the solution you'd like
With the settings
update_focused_file = { enable = true, update_root = false }
when I open a file in repo A the tree is focused on the folder where the file is located and the root folder is the repo's base, where.git
folder is. This is working as expected. However, if I open another file in repo B, the tree doesn't update to repo B's base.I tried setting
update_focused_file.update_root = true
and the tree does follows the file in repo B, however, the root folder is not repo B's base, but the folder deep inside where the file is located. I would like for nvim-tree to always make the repo's base the root folder, not the folder where the file is located as root.Describe alternatives you've considered
I looked through the docs have not seen a option to achieve what I mentioned.
Additional context
N/A
Beta Was this translation helpful? Give feedback.
All reactions