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

changing directories from nvim-tree not recognized - With Workaround #178

Open
zwhitchcox opened this issue Nov 6, 2022 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@zwhitchcox
Copy link
Contributor

zwhitchcox commented Nov 6, 2022

Describe the bug
If you have nvim-tree installed, you can change the pwd, the buffers are not deleted. These buffers have a different pwd than the current pwd, which means that if you now open another file, you have to different buffers with different pwd's. This causes session corruptions when you try to restore the session, because it's trying to restore buffers from two different sessions.

To Reproduce
Steps to reproduce the behavior:

  1. Install nvim-tree
  2. Open a directory with nvim, open a file, and save the session
  3. Open nvim-tree (with :NvimTreeOpen), and change to the parent directory (u). The buffer from the previous session is not deleted
  4. :SaveSession again, and open a file in the parent directory
  5. Mayhem ensues

Expected behavior
I don't really think autosession is going to be able to solve this, other than by providing instructions on how to work with nvim-tree, I just wanted to post my workaround for anyone else who is struggling.

WORKAROUND

So, there are two main problems.

1. nvim-tree makes no attempt to be compatible with sessions.

So, basically you have to close nvim-tree before you save the session, which you can do with hooks:

local function close_nvim_tree()
  require('nvim-tree.view').close()
end
local function open_nvim_tree()
  require('nvim-tree').open()
end
require("auto-session").setup {
  log_level = "error",
  pre_save_cmds = {close_nvim_tree},
  post_save_cmds = {open_nvim_tree},
  post_open_cmds = {open_nvim_tree},
  post_restore_cmds = {open_nvim_tree},
  cwd_change_handling = {
    restore_upcoming_session = true,
    pre_cwd_changed_hook = close_nvim_tree,
    post_cwd_changed_hook = open_nvim_tree,
  },
}

2. nvim-tree uses lcd instead of cd, which doesn't trigger the hooks

This can be fixed in your nvim-tree config:

nvim_tree.setup {
  actions = {
    change_dir = {
      global = true
    }
  },
}

That's all

There might be problems, as I just figured this out, but hopefully it will help someone else out there who's struggling with this.

@zwhitchcox zwhitchcox added the bug Something isn't working label Nov 6, 2022
@zwhitchcox zwhitchcox changed the title changing directories from nvim-tree not recognized changing directories from nvim-tree not recognized - With Workaround Nov 6, 2022
@zwhitchcox
Copy link
Contributor Author

Just going to leave my full vim config here in case I missed something, so you can see the full configuration.

https://github.com/zwhitchcox/config.nix/tree/master/configs/nvim/lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants