Skip to content
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

Unexpected behaviour when opening session with nvim-tree #50

Closed
brapifra opened this issue Aug 14, 2021 · 13 comments
Closed

Unexpected behaviour when opening session with nvim-tree #50

brapifra opened this issue Aug 14, 2021 · 13 comments

Comments

@brapifra
Copy link

Hey!

First of all, congrats on the plugin :)

Unfortunately, I encounter this E95: Buffer with this name already exists error when opening nvim after closing it with nvim-tree open:
image

Not sure if it's something that needs to be fixed on your end or on nvim-tree's end though. Let me know!

@rmagatti
Copy link
Owner

Hey @brapifra I'm guessing this is because an nvim-tree buffer doesn't support being saved on a session, at least with your current sessionopts.

I don't use nvim-tree so I wouldn't know much further than that. What I can tell you is that this plugin merely wraps mksession functionality, so I doubt it's something I could fix on my end.

That being said, what I've seen people do is use the session hooks to close any tree-like plugin's windows before saving the session so you at least don't see what you're currently seeing.

I hope that helps at least a bit 😄

@brapifra
Copy link
Author

Thanks for the info @rmagatti!
Makes sense, I'll give that a try :)

@sujaybokil
Copy link

Hii @brapifra, I had the same issue which I solved through hooks and I will leave my config down here for you which would solve it hopefully. Adding the last 2 options (which are hooks) would take care of the issue.

local opts = {
  log_level = 'info',
  auto_session_enable_last_session = false,
  auto_session_root_dir = vim.fn.stdpath('data').."/sessions/",
  auto_session_enabled = false,
  auto_save_enabled = false,
  auto_restore_enabled = false,
  auto_session_suppress_dirs = nil,
  pre_save_cmds = {"tabdo NvimTreeClose"},
  post_restore_cmds = {"tabdo NvimTreeRefresh"}
}

require('auto-session').setup(opts)

@brapifra
Copy link
Author

Hey @sujaybokil
For some reason, I can't make your config working on my neovim. I did this and it works like a charm:

    use {
      "rmagatti/auto-session",
      config = function()
        require("auto-session").setup {
          pre_save_cmds = {"NvimTreeClose"}
        }
      end
    }

@rmagatti
Copy link
Owner

Closing since it looks like hooks cover the necessary cases.

@mattleong
Copy link

pre_save_cmds = {"NvimTreeClose"}

Can open a new issue if needed. But this hook alone doesn't properly seem to close nvim-tree anymore. Can anyone else verify?

@egidijusz
Copy link

pre_save_cmds = {"NvimTreeClose"}

Can open a new issue if needed. But this hook alone doesn't properly seem to close nvim-tree anymore. Can anyone else verify?

I can confirm.

@rmagatti
Copy link
Owner

rmagatti commented Dec 6, 2021

Hey guys, so unless there's an issue with the hook itself, this is probably something on the nvim-tree side of things. Let me know if I can help with anything though!

@r7vme
Copy link

r7vme commented Dec 11, 2021

Works for me

let g:auto_session_pre_save_cmds = ["lua require'nvim-tree'.setup() | tabdo NvimTreeClose"]

@im-n1
Copy link

im-n1 commented Jan 10, 2022

Works for me

let g:auto_session_pre_save_cmds = ["lua require'nvim-tree'.setup() | tabdo NvimTreeClose"]

Cannot confirm on nvim 0.5

@r7vme
Copy link

r7vme commented Jan 10, 2022

Actually seems smth was updated, and today with newer neovim or plugins I fixed it to smth like

let g:auto_session_pre_save_cmds = ["lua require'nvim-tree'.setup()", "tabdo NvimTreeClose"]

@im-n1
Copy link

im-n1 commented Jan 11, 2022

still no luck

@timtyrrell
Copy link

On neovim nightly....

This does not work:

require('auto-session').setup {
  -- other config above
  pre_save_cmds = {"tabdo NvimTreeClose"}
}

This works:

require('auto-session').setup {
  -- other config above
  pre_save_cmds = {"lua require'nvim-tree'.setup()", "tabdo NvimTreeClose"}
}

"Works" means if I close neovim with a nvim-tree buffer open, when I reopen vim, that buffer is gone and not open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants