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
-
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-vinegar
user for a long time, as I usually only need to skim over the directory, andnetrw
is good enough for that.vim-vinegar
madenetrw
easily accessible with the single"-"
keymap.But,
netrw
is 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.x
toAstroNvim v3.x
and I finally decided to dive deeper into theneo-tree.nvim
configuration and set it up to my liking. The core options are already there - theNeotree position=current reveal
will open the working directory with focus on the current file, and there is an option to useneo-tree
to open directories withhijack_netrw_behavior
.2 major things were lacking, though. There is no
"-"
keymap, and using theneo-tree
in place messes up the alternate file.Adding the
"-"
keymap was fairly easy - I set the global keymap for"-"
to open theneo-tree
in place if not already in theneo-tree
buffer, and set theneo-tree
specific 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
BufWinEnter
event to store the alternate buffer number as a window variable on entering theneo-tree
buffer. 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-tree
buffer. I checked the source code and decided that I will just remove theaugroup
that produces the notification. The relevant function restores window-local options for theneo-tree
buffer, and I am sure that I can do without this functionality; I have never set window-local options forneo-tree
anyway.Here is the final
neo-tree.lua
file from my plugins directory. It islazy.nvim
plugin 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.nvim
is a much better tree explorer thannetrw
- it is much more stable and has sensible keymaps, which are easier to customize. With additional functions fromAstroNvim
it covers all my directory browsing needs and some of my file-management needs.Thanks, @cseickel for the
nvim-tree.nvim
plugin and to @mehalter for theAstroNvim
config, 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