I am coming from coc-explorer and the only thing I miss is the hjkl navigation in the file tree. for example l to go into a directory, h to come out of it or "fold" it. I could map l to <cr> but then to get out of the node/folder binding h will need some kind of condition which make me go up and not into a directory. I am not familiiar with your code or lua, is this something you can implement?
I use following mappings, which bring some of the functionality you mentioned:
vim.g.nvim_tree_bindings = {
edit = {"<CR>", "o", "l"},
close_node = {"<S-CR>", "<BS>", "h"}
}
Hi, i'm quite busy atm and will not be able to work on this plugin. We'll keep this open as i think other users talked about this in the past and i think it would be a great feature to implement.
I use following mappings, which bring some of the functionality you mentioned:
vim.g.nvim_tree_bindings = { edit = {"<CR>", "o", "l"}, close_node = {"<S-CR>", "<BS>", "h"} }
@cloggier Im getting this error when I use this:
Error executing vim.schedule lua callback: ....config/nvim/plugged/nvim-tree.lua/lua/nvim-tree/lib.lua:247: Expected lua string
Okay I managed to fix this error by doing this:
lua << EOF
local function get_lua_cb(cb_name)
return string.format(":lua require'nvim-tree'.on_keypress('%s')<CR>", cb_name)
end
vim.g.nvim_tree_bindings = {
["<cr>"] = get_lua_cb("edit"),
["<s-cr>"] = get_lua_cb("close_node"),
["o"] = get_lua_cb("edit"),
["<BS>"] = get_lua_cb("close_node"),
["l"] = get_lua_cb("edit"),
["h"] = get_lua_cb("close_node"),
}
EOF
It's not the most elegant, but it works.
could we consider this issue fixed then ?
I tried what @ahmedkhalf suggested, but h is still not working as required. pressing h takes the cursor to the top of the file-browser buffer, does not "close-node".
I tried what @ahmedkhalf suggested, but
his still not working as required. pressing h takes the cursor to the top of the file-browser buffer, does not "close-node".
hum, very weird. For me pressing h brings me to the top when im not over a folder (when im in the top level folder) or when the hovered folder is closed. But for child folders that are open pressing h closes the folder.
Regardless, I think this buffer navigation should be inside of NvimTree and enabled using a simple setting, rather than having the user define the keybindings like that. The current keybind hack doesn't really work all that well because of the cursor teleportation issue you mentioned, so this strengthen the point that having it "natively" written could solve this jankiness.
I tried what @ahmedkhalf suggested, but
his still not working as required. pressing h takes the cursor to the top of the file-browser buffer, does not "close-node".hum, very weird. For me pressing h brings me to the top when im not over a folder (when im in the top level folder) or when the hovered folder is closed. But for child folders that are open pressing h closes the folder.
I think we are trying to get different types of navigation with this, my idea was to have navigation like coc-explorer. It doesn't need you to be on the node folder to collapse it, you can be inside the node and pressing h will close the first outer node.
You can never close/collapse the outest/first node inside of NvimTree (It's always visible as far as im aware). However if you are inside of a child node pressing h on any file inside that child node will collapse it.
You can never close/collapse the outest/first node inside of NvimTree (It's always visible as far as im aware). However if you are inside of a child node pressing h on any file inside that child node will collapse it.
Okay so I meant the innermost node above the cursor, I hope it clarifies what it means..
But anyway, you are right about this being an internal feature on nvim-tree.
Im still not sure what you mean, so I hope this video clarifies it, here what I get when pressing h in coc-explorer and nvimtree
Pressing h on NvimTree (with keybindings defined:
Pressing h on coc-explorer:
Please let me know what is the unintended behavior.
The behavior in both the videos is the one I expect, but using the same snippet that you shared I get different behavior.
which behavior are you talking about ? Maybe we could track this issue.
I'll add this mapping so users don't have to override it themselves.
So, for some reason when I use the snippet that @ahmedkhalf provided, it doesn't bind the keys, so I went and changed the source code to add the desired keys to respective functions in config.lua, and now its working as expected.
maybe you set the variable too late. I'm not sure, i'll look into it when i have some time
I was about to open a similar issue requesting options like traversing between sibling directories, going to the last active buffer position, and some other stuff.
If this issue hasn't been fixed yet, I could try to implement that alongside my suggestions maybe?
i guess these might not be too hard to implement, go for it :)
@Chaitanyabsprip I'm submitting a Pull Request but you can achieve the result you want by now just doing this:
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
vim.g.nvim_tree_bindings = {
['h'] = tree_cb('close_node'),
['l'] = tree_cb('edit'),
}
@Chaitanyabsprip has this issue been solved for you? Maybe you can close this if so.