Skip to content

nvim-tree feature migration #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
axieax opened this issue Mar 27, 2022 · 17 comments
Closed
3 tasks done

nvim-tree feature migration #211

axieax opened this issue Mar 27, 2022 · 17 comments
Labels
enhancement New feature or request how-to

Comments

@axieax
Copy link

axieax commented Mar 27, 2022

Hi, I'm currently migrating from nvim-tree and was wondering whether the following features are supported (feature requests if not):

  • group empty directories (compact folders that only contain a single folder into one node in the file tree)
  • vim.ui.input instead of popup for creating files etc. (like nvim-tree)
  • netrw_hijack behaviour of open_default but for full-width window instead of the side panel (open_current replaces current, which isn't ideal)
@cseickel
Copy link
Contributor

[ ] group empty directories (compact folders that only contain a single folder into one node in the file tree)

This feature does not exist.

@cseickel
Copy link
Contributor

  • vim.ui.input instead of popup for creating files etc. (like nvim-tree)

Yes, add this to your config:

  use_popups_for_input = false, -- If false, inputs will use vim.ui.input() instead of custom floats.

@cseickel
Copy link
Contributor

[x] netrw_hijack behaviour of open_default but for full-width window instead of the side panel (open_current replaces current, which isn't ideal)

If you want to open Neotree in a split, but not the current one, you can use the "open_current" behavior but use :split . and :vsplit . to open it.

@axieax
Copy link
Author

axieax commented Mar 27, 2022

Thanks for the quick response and help! For the netrw_hijack behaviour, I was more describing the following scenario:

  • User opens Neovim to a directory
  • neo-tree automatically opens as a full width buffer (which can be closed, unlike open_current)
  • Selecting a file from the neo-tree buffer will close the buffer and open the file

Running <ctrl-w>o after loading seems to be closer to this behaviour than :split . and :vsplit ..

EDIT: I just came across the floating popup option and I love it, so I'm using that now (so no more <ctrl-w>o unfortunately)

@cseickel
Copy link
Contributor

  • User opens Neovim to a directory
  • neo-tree automatically opens as a full width buffer (which can be closed, unlike open_current)
  • Selecting a file from the neo-tree buffer will close the buffer and open the file

Sorry but I think I am confused, what you describe above is the current behavior if you specify hijack_netrw_behavior = "open_current" and you open nvim to a directory. Does it not work that way for you?

@axieax
Copy link
Author

axieax commented Mar 27, 2022

open_current's behaviour is pretty much what I would like. Only thing is that when that buffer is active, it pretty much "consumes" my buffers and I cannot move to my other tabs without using my mouse for some reason. It works fine if neo-tree is opened as a separate buffer though.

neotree.mp4

@cseickel
Copy link
Contributor

In the video above you opening nvim with two buffers, one is a file and one is a dir. The strange behavior you are experiencing is due to these facts:

  • You are using a plugin that displays buffers as tabs
  • The buffer with a file starts out as the "active" buffer in this situation
  • The hijack does not happen until you actually show the directory buffer
  • Once the directory buffer is hijacked and turned into a "neo-tree" buffer, it becomes unlisted and your bufferline plugin stops showing a tab for it.

I am still confused as to why you would open a file and directory at the same time. Did you want them to open in splits like the -o option would do with two files?

@axieax
Copy link
Author

axieax commented Mar 27, 2022

Thanks for the followup. I guess the question is more whether it's possible to make the hijacked buffer "listed" rather than "unlisted". The main thing I want to do is navigate between my buffers after directory view is hijacked (which does not work from the video).

I am still confused as to why you would open a file and directory at the same time.

For my workflow, I like to open nvim with the files/directories which I will be working on, then further selecting the files within directories to open (eliminates the need to find and search for the subfiles). In this case, I would like the directory listing to be treated as an "active" buffer (like for a normal file opened to the full-width of the editor). Sorry for the confusion!

@cseickel
Copy link
Contributor

OK, in that case all you need is the ability to override the local options with a setlocal buflisted. This is related to #155.

@cseickel cseickel added the enhancement New feature or request label Mar 27, 2022
@axieax
Copy link
Author

axieax commented Mar 28, 2022

Oo I just tried adding vim.cmd("au! FileType neo-tree setlocal buflisted"), and it seems like the buffer becomes active before quickly becoming inactive again (and opened files disappear from the buffer line as well - which seems to be a normal issue regardless of autocmd). I am doing this incorrectly lol.

nt2.mp4

@cseickel
Copy link
Contributor

Because I use my own event system, the timing can be a little off. This will work around that:

autocmd Filetype neo-tree lua vim.schedule(function() vim.cmd("setlocal buflisted") end)

@axieax
Copy link
Author

axieax commented Mar 28, 2022

Works perfectly now. Thank you so much for the followup help!

@axieax axieax closed this as completed Mar 28, 2022
@gegoune
Copy link

gegoune commented Mar 28, 2022

@cseickel apologies for hijacking the issue, but it seems like it's related to latest discussion here.

I have following autocmds set for nvim-tree:

vim.api.nvim_create_autocmd({ 'WinEnter', 'BufWinEnter' }, {
  pattern = 'NvimTree_*',
  callback = function()
    vim.api.nvim_command 'highlight! Cursor blend=100'
    vim.opt.guicursor = { 'n:Cursor/lCursor', 'v-c-sm:block', 'i-ci-ve:ver25', 'r-cr-o:hor2' }
  end,
})

vim.api.nvim_create_autocmd({ 'BufLeave', 'WinClosed' },{
  pattern = 'NvimTree_*',
  callback = function()
    vim.api.nvim_command 'highlight! Cursor blend=NONE'
    vim.opt.guicursor = { 'n-v-c-sm:block', 'i-ci-ve:ver25', 'r-cr-o:hor20' }
  end,
})

I tried to replicate the same for neo-tree by changing pattern to neo-tree but it does not seem to be working at all, no events get triggered. Do you know what I am doing wrong here maybe?
(this is to hide cursor in tree views and restore it after leaving tree's window)

@cseickel
Copy link
Contributor

I think you may have a timing issue @gegoune. I'm not sure the name is applied before those events fire.

I think it will be faster for me to just do #155 than to work this out. I'll do that tonight.

@cseickel
Copy link
Contributor

@gegoune, see #155 (comment)

That code is in main right now, I will probably release it to 2.x tomorrow.

@gegoune
Copy link

gegoune commented Mar 29, 2022

@cseickel Perfect, that's working as expected now, thanks!

@cseickel
Copy link
Contributor

@axieax I just added the group empty directories option: #216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request how-to
Projects
None yet
Development

No branches or pull requests

3 participants