neo-tree.nvim as the split explorer (netrw + vim-vinegar-like behavior)
#813
yehorb
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I want to share my configuration for a
neo-tree.nvim, which I use mostly as the split explorer. As there are no explicit examples for such a use case, I think this will be useful for future users that are looking for the split explorer setup.I was a
netrw+vim-vinegaruser for a long time, as I usually only need to skim over the directory, andnetrwis good enough for that.vim-vinegarmadenetrweasily accessible with the single"-"keymap.But,
netrwis far from perfect - its default keymaps are not intuitive at all, and I encountered visual bugs a lot, especially with the tree style listing (g:netrw_liststyle = 3).Recently I have been switching from
AstroNvim v2.xtoAstroNvim v3.xand I finally decided to dive deeper into theneo-tree.nvimconfiguration and set it up to my liking. The core options are already there - theNeotree position=current revealwill open the working directory with focus on the current file, and there is an option to useneo-treeto open directories withhijack_netrw_behavior.2 major things were lacking, though. There is no
"-"keymap, and using theneo-treein place messes up the alternate file.Adding the
"-"keymap was fairly easy - I set the global keymap for"-"to open theneo-treein place if not already in theneo-treebuffer, and set theneo-treespecific window keymap to the simple function what will navigate to the current node's parent.Correctly tracking the alternate file was a bit more interesting problem to solve. I decided to use the
BufWinEnterevent to store the alternate buffer number as a window variable on entering theneo-treebuffer. Then I set the global<C-^>keymap to a function that checks the variable and opens the relevant buffer if the variable is set. If the variable is not set, it uses the existing alternate buffer number.1 minor thing was an annoying
"Window settings restored"notification every time I opened aneo-treebuffer. I checked the source code and decided that I will just remove theaugroupthat produces the notification. The relevant function restores window-local options for theneo-treebuffer, and I am sure that I can do without this functionality; I have never set window-local options forneo-treeanyway.Here is the final
neo-tree.luafile from my plugins directory. It islazy.nvimplugin spec, and it is not even a full spec, as I useAstorNvim, but the relevant functions and configuration is visible and should be easily portable to other plugin managers.I have been using this setup for the past week or so, and it feels familiar, but also better.
neo-tree.nvimis a much better tree explorer thannetrw- it is much more stable and has sensible keymaps, which are easier to customize. With additional functions fromAstroNvimit covers all my directory browsing needs and some of my file-management needs.Thanks, @cseickel for the
nvim-tree.nvimplugin and to @mehalter for theAstroNvimconfig, you make my development time more enjoyable.I hope you found this write-up useful, have a nice day, and happy nvimming!
Beta Was this translation helpful? Give feedback.
All reactions