neo-tree.nvim
neo-tree.nvim copied to clipboard
Navigate to parent directory of the current file
Nerdtree had a pretty good feature where you could open nerdtree, focus on a file, then if you press "P", it would navigate to parent directory of the file and you would keep climbing the tree until you reached the root of the project.
In the example bellow, if you pressed "P" (or any other key mapped to this functionality) it would navigate to the "bye" directory, then again pressing "P" would navigate you to "hello" directory and so on.

Is there a way to achieve this with neo-tree?
You can do that with a custom command. This discussion has an example of a slightly more complicated version: https://github.com/nvim-neo-tree/neo-tree.nvim/discussions/163
If you just want to go up one directory every time, you can do that with:
require("neo-tree").setup({
window = {
mappings = {
["P"] = function(state)
local node = state.tree:get_node()
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
end
}
}
})
@aakashsigdel does @cseickel comment resolve your issue? Think we can close this issue out?
Closing as solved.
["P"] = functions
It should be function
["P"] = functions
It should be
function
I fixed the example @FrankFang
How does this work for navigating up, from the parent directory?
Once you get to the top main directory, given where you opened nvim
from - you can't go any further up 🤔
I like the solution and implemented it but same question as @thewatts.
If already at the top of neotree
I want to be able to navigate to the neotree
parent folder. If I keep hitting "P" at the top of the neotree
I SHOULD be able to eventually get to /
Changing the root folder of neo-tree requires a lot of computation throughout the whole tree which is a heavy task compared to other operations.
I strongly do not recommend to have a keybind that may move cwd accidentally as, you know, you don't want to accidentally freeze neovim.
Instead please be patient and see that the redraw has finished instead of spamming the key when you are going to move the root.
I understand it may be inconvenient from time to time but I recommend to have a dedicated key to move the root just to be safe (by default it's <BS>
mapped to "navigate_up").
@thewatts I didn't notice your comment :P
It's <BS>
(backspace) by default mapped to "navigate_up"