preservim / nerdtree

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

cant open file unless in that directory? #931

Closed jeffwillette closed 5 years ago

jeffwillette commented 5 years ago

Environment

let g:NERDTreeDirArrowExpandable = '  '
let g:NERDTreeDirArrowCollapsible = '  '

nnoremap <leader>[ :NERDTreeToggle<CR>
let g:NERDTreeWinSize = 50
let g:NERDTreeQuitOnOpen = 1
let g:NERDTreeAutoDeleteBuffer = 1

augroup nerdtree
    autocmd FileType nerdtree setlocal signcolumn=no modifiable
augroup END

Process

  1. open nerdtree
  2. open dir with
  3. try to o or <CR> on file to open it

Current Result

nothing happens, I have to cd nerdtree with C into the directory and only then can I o or <CR> to open the file

Expected Result

I used to use nerdtree in the past and this worked. I recently switched back and I cannot find any options or issues relating to this, but it doesn't work for me anymore

Screenshot(s)

Possible Fix

celsodantas commented 5 years ago

I'm having the same issue with current HEAD.

celsodantas commented 5 years ago

So I noticed that I was having that issue if using version:

vim: stable 8.1.0850 (bottled), HEAD

I'm on a Mac, and that version was installed by brew install vim. I've fallback to the default in Mac: VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 17 2018 17:24:51) and it works now.

Maybe an incompatibility with the 8.1 version of VIM? Of something that the brew version didn't compile it with?

PhilRunninger commented 5 years ago

If you could grab the output of :version for both 8.1 and 8.0, we might see whether a feature being turned on or off is making a difference. I'm using

VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 16 2018 11:09:46)
macOS version
Included patches: 1-529

and I don't see this issue. I did compile it with a lot of features turned on though.

celsodantas commented 5 years ago

This is the default on the Mac 10.14.2, and it works:

vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 17 2018 17:24:51)
Included patches: 1-503, 505-680, 682-1283
Compiled by root@apple.com
Normal version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    -mouse_sgr       +tag_old_static
-arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           -mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     -termguicolors
-browse          -footer          +multi_byte      -terminal
+builtin_terms   +fork()          +multi_lang      +terminfo
+byte_offset     -gettext         -mzscheme        +termresponse
+channel         -hangul_input    +netbeans_intg   +textobjects
+cindent         +iconv           +num64           +timers
-clientserver    +insert_expand   +packages        +title
-clipboard       +job             +path_extra      -toolbar
+cmdline_compl   +jumplist        -perl            +user_commands
+cmdline_hist    -keymap          +persistent_undo +vertsplit
+cmdline_info    +lambda          +postscript      +virtualedit
+comments        -langmap         +printer         +visual
-conceal         +libcall         -profile         +visualextra
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             -rightleft       +windows
+diff            +menu            +ruby/dyn        +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
-emacs_tags      -mouseshape      +startuptime     -xpm
+eval            -mouse_dec       +statusline      -xsmp
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard
+extra_search    -mouse_jsbterm   +syntax          -xterm_save
-farsi           -mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa

And this one, installed using brew install vim doesn't:

vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jan 31 2019 16:43:52)
macOS version
Included patches: 1-850
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        -toolbar
-clientserver      +job               +perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua               +ruby              +windows
+dialog_con        +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
-dnd               +mouse             +startuptime       -xim
-ebcdic            -mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -lintl -framework AppKit  -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.14 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.28.1/lib/perl5/5.28.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc  -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -framework CoreFoundation  -lruby.2.6
jeffwillette commented 5 years ago

I'm actually on nvim, but here is my version info

VIM v0.3.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -W
all -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=aut
o -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/b
uild/config -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Content
s/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/build/src/nvim/auto -I
/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/build/include
Compiled by brew@Mojave.local

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.3.4/share/nvim"
thameera commented 5 years ago

I have the same issue and has made NERDTree unusable for the most part (unless I cd to the dir as deltaskelta suggested).

vim --version

``` VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 11 2019 17:46:54) macOS version Included patches: 1-1150 Compiled by Homebrew Huge version without GUI. Features included (+) or not (-): +acl +extra_search +mouse_netterm -tag_old_static +arabic -farsi +mouse_sgr -tag_any_white +autocmd +file_in_path -mouse_sysmouse -tcl +autochdir +find_in_path +mouse_urxvt +termguicolors -autoservername +float +mouse_xterm +terminal -balloon_eval +folding +multi_byte +terminfo +balloon_eval_term -footer +multi_lang +termresponse -browse +fork() -mzscheme +textobjects ++builtin_terms +gettext +netbeans_intg +textprop +byte_offset -hangul_input +num64 +timers +channel +iconv +packages +title +cindent +insert_expand +path_extra -toolbar -clientserver +job +perl +user_commands +clipboard +jumplist +persistent_undo +vartabs +cmdline_compl +keymap +postscript +vertsplit +cmdline_hist +lambda +printer +virtualedit +cmdline_info +langmap +profile +visual +comments +libcall -python +visualextra +conceal +linebreak +python3 +viminfo +cryptv +lispindent +quickfix +vreplace +cscope +listcmds +reltime +wildignore +cursorbind +localmap +rightleft +wildmenu +cursorshape +lua +ruby +windows +dialog_con +menu +scrollbind +writebackup +diff +mksession +signs -X11 +digraphs +modify_fname +smartindent -xfontset -dnd +mouse +startuptime -xim -ebcdic -mouseshape +statusline -xpm +emacs_tags +mouse_dec -sun_workshop -xsmp +eval -mouse_gpm +syntax -xterm_clipboard +ex_extra -mouse_jsbterm +tag_binary -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/usr/local/share/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.14 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.28.1/lib/perl5/5.28.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -framework CoreFoundation -lruby.2.6 ```

PhilRunninger commented 5 years ago

I need more information to go on to reproduce this, because it's working on my setup. I just upgraded my homebrewed vim 8.1 this morning, and I now have patches 1-1174 and exactly the same features as @thameera. My first guess is another plugin could be doing something strange here. Have you tried uninstalling other plugins to see if there is any interference? Later today, I'll create a new branch with some logging statements in it, which you can use to help me see what's happening on your end.

PhilRunninger commented 5 years ago

@deltaskelta , @celsodantas , @thameera , I created a branch that has some debugging statements in it. Could you go to your nerdtree repository folder and issue these commands:

git pull
git checkout must_cd_before_open

Then open vim, and run through the scenarios you've described. Grab the messages that are output, and post them in the issue. Every function call along the way for opening a file should be displayed.

Thanks, Phil

jeffwillette commented 5 years ago

I followed what you said. When I open a file in the same directory, I get this output...

CWD: /Users/Jeff/.config/nvim/plugged/nerdtree
NERDTree Root: /Users/Jeff/.config/nvim/plugged/nerdtree
activateNode(/Users/Jeff/.config/nvim/plugged/nerdtree/CHANGELOG)
 TreeFileNode.activate({'reuse': 'all', 'where': 'p'})
 TreeFileNode.open({'reuse': 'all', 'where': 'p'})
  Opener.New(/Users/Jeff/.config/nvim/plugged/nerdtree/CHANGELOG, {'reuse': 'all', 'where': 'p'})
  Opener.open(/Users/Jeff/.config/nvim/plugged/nerdtree/CHANGELOG)
   Opener._openFile()
   Opener._reuseWindow()
   Opener._gotoTargetWin()
   Path.edit()
    vim command: edit CHANGELOG
"CHANGELOG" 179L, 8491C

but when I try to open a file in a different directory, nothing happens at all. I was able to narrow it down to one NERDTree setting.

In my config I have the following two lines (it is an expanded and collapsed folder unicode symbol which I had added some whitespace around to display better in the tree. If the collapsible symbol has a trailing space, I get the error.

let g:NERDTreeDirArrowExpandable = '  '
let g:NERDTreeDirArrowCollapsible = '  '

but if I remove the space, I do not get an error.

let g:NERDTreeDirArrowExpandable = '  '
let g:NERDTreeDirArrowCollapsible = ' '

So I think I will just remove all the whitespaces around the characters for now, not sure if it is worth fixing in NERDTree or just noting in the docs. Can anyone else confirm this is what caused their issue?

celsodantas commented 5 years ago

@deltaskelta same thing with me.

If I don't set

g:NERDTreeDirArrowExpandable
g:NERDTreeDirArrowCollapsible

when I try to select something in another folder, nothing happens. No output. If I set g:NERDTreeDirArrowCollapsible with no right space, it works and I get an output.

here's the output for a file in the same directory:

CWD: /Users/celsodantas/.dotfiles/vim
NERDTree Root: /Users/celsodantas/.dotfiles/vim
activateNode(/Users/celsodantas/.dotfiles/vim/vimrc)
 TreeFileNode.activate({'reuse': 'all', 'where': 'p'})
 TreeFileNode.open({'reuse': 'all', 'where': 'p'})
  Opener.New(/Users/celsodantas/.dotfiles/vim/vimrc, {'reuse': 'all', 'where': 'p'})
  Opener.open(/Users/celsodantas/.dotfiles/vim/vimrc)
   Opener._openFile()
   Opener._reuseWindow()
  _reuseWindow() is true

and for one in another directory wit the "fix":

CWD: /Users/celsodantas/.dotfiles/vim
NERDTree Root: /Users/celsodantas/.dotfiles/vim
activateNode(/Users/celsodantas/.dotfiles/vim/colors/xterm16.vim)
 TreeFileNode.activate({'reuse': 'all', 'where': 'p'})
 TreeFileNode.open({'reuse': 'all', 'where': 'p'})
  Opener.New(/Users/celsodantas/.dotfiles/vim/colors/xterm16.vim, {'reuse': 'all', 'where': 'p'})
  Opener.open(/Users/celsodantas/.dotfiles/vim/colors/xterm16.vim)
   Opener._openFile()
   Opener._reuseWindow()
   Opener._gotoTargetWin()
   Path.edit()
    vim command: edit colors/xterm16.vim
"colors/xterm16.vim" 811L, 36180C
jeffwillette commented 5 years ago

Thanks!