preservim / nerdtree

A tree explorer plugin for vim.
Do What The F*ck You Want To Public License
19.66k stars 1.45k forks source link

Navigating directory tree broken in WSL filesystem #1341

Closed lucky-bai closed 1 year ago

lucky-bai commented 1 year ago

Steps to reproduce:

  1. Open a file in WSL in GVim, for example, \\wsl.localhost\Ubuntu-20.04\home\bai\blah\test.txt
  2. Open NERDTree (:NERDTree)
  3. Go up a directory (u shortcut)
  4. Directory appears empty

Expected behavior: I should see my files in \\wsl.localhost\Ubuntu-20.04\home\bai, but it appears empty in the NERDTree explorer.

My VIM version: 8.2, using GVim and Windows 11. Not sure which version of NERDTree I have, but installed it sometime in 2021.

rzvxa commented 1 year ago

@luckytoilet Hey mate sorry to ping you on this issue, I can confirm this problem happens when you are accessing WSL files from Windows, I suggest you use Vim inside of the WSL for editing those files as NERDTree has no idea that it is working on files in a Linux machine and may result in some unwanted issues. I suggest that you update your NERDTree and set this flag NERDTreeCaseSensitiveFS to 1 to prevent some of these problems. I don't think your case is general enough to change the NERDTree to work nicely in this environment, as it comes with the cost of rebuilding the tree. On the other hand, NERDTree is highly customizable you can just overwrite the u binding to something like this to fix your problem:

function! NERDTreeCustomCWD(dirnode)
  call a:dirnode.path.getParent().changeToDir()
  call NERDTreeCWD()
endfunction

function! NERDTreeCustomCWDBinding()
  call NERDTreeAddKeyMap({
         \ 'key': 'u',
         \ 'callback': 'NERDTreeCustomCWD',
         \ 'quickhelpText': 'cd to the parent directory',
         \ 'scope': 'DirNode' })
endfunction

autocmd VimEnter * call NERDTreeCustomCWDBinding()

read more about this with :help NERDTreeAddKeyMap.

I'm going to close this issue, feel free to open it if you have any further questions.