Collapse and expand the tree with left/right arrows and/or h/l keys? #2687
Unanswered
cadamsdotcom
asked this question in
Q&A
Replies: 2 comments 5 replies
-
This is all possible using API. Take a look at the first recipe which should cover a lot of your use cases. |
Beta Was this translation helpful? Give feedback.
0 replies
-
been a long time since I set it up (left commented old code,) got here after latest update where thank you for the hint @alex-courtis, sorted with on_attach = function (bufnr)
local opts = { buffer = bufnr }
api.config.mappings.default_on_attach(bufnr)
local lefty = function ()
local node_at_cursor = lib.get_node_at_cursor()
if (node_at_cursor.name == ".." or node_at_cursor.nodes) and node_at_cursor.open then
api.node.open.edit()
-- lib.expand_or_collapse(node_at_cursor)
else
api.node.navigate.parent()
end
end
local righty = function ()
local node_at_cursor = lib.get_node_at_cursor()
if (node_at_cursor.name == ".." or node_at_cursor.nodes) and not node_at_cursor.open then
api.node.open.edit()
-- lib.expand_or_collapse(node_at_cursor)
end
end
vim.keymap.set("n", "h", lefty , opts )
vim.keymap.set("n", "<Left>", lefty , opts )
vim.keymap.set("n", "<Right>", righty , opts )
vim.keymap.set("n", "l", righty , opts )
end,
in the recipe it's clearly written that -- expand or collapse folder
api.node.open.edit() but it still took me some time to wrap my head to the fact that |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!,
In macOS Finder windows, you can use the left and right arrows to collapse and expand folders and move into and out of the hierarchy. Here's an example: https://www.youtube.com/watch?v=Dx9_RQLqShI&t=401s
It makes for a quick way to descend up and down the folder hierarchy, expanding and collapsing as you go - and it's standard in macOS tree views so I didn't know how much I'd miss it!
Wondering if this behavior can be reproduced in nvim-tree?
A quick glance at the help, and a little play with it out of the box, suggests building this could be possible by inspecting what's under the cursor and deciding how to behave.
On pressing
l
eitherOn pressing
h
almost the reverseI'm 100% new to neovim and lua so would love some guidance on how to do this!
Beta Was this translation helpful? Give feedback.
All reactions