nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 6318406f6606481b5e3a42a5754096063d996587
parent 496b61ead1acd80128164cce5c2ff8e89c42ded2
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date:   Sun, 29 Sep 2019 11:28:59 -0400

If file path doesn't exist, :NERDTreeFind its parent directory instead. (#1043)

* If file path doesn't exist, :NERDTreeFind its parent directory instead.

This happens in the following scenario:
```
:edit path/new_file
:NERDTreeFind
```
Instead of an error message about an **invalid path**, this change will
now find the parent directory instead. It will not work if the new file
is **path/new_folder/new_file**, and that's OK because even vim itself
cannot handle both the new folder and the new file; `:w` won't create
the new folder.

* Update version number in change log.

* Change version change from PATCH to MINOR.

Diffstat:
MCHANGELOG.md | 2++
Mautoload/nerdtree/ui_glue.vim | 3+++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -1,5 +1,7 @@
 # Change Log
 
+#### 6.1...
+- **.0**: If file path doesn't exist, :NERDTreeFind its parent directory instead. (PhilRunninger) [#1043](https://github.com/scrooloose/nerdtree/pull/1043)
 #### 6.0...
 - **.1**: Reintroduce necessary variable mistakenly removed. (PhilRunninger) [#1040](https://github.com/scrooloose/nerdtree/pull/1040)
 - **.0**: Make the behavior of window splits consistent (dragonxlwang, PhilRunninger) [#1035](https://github.com/scrooloose/nerdtree/pull/1035)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -284,6 +284,9 @@ endfunction
 " FUNCTION: s:findAndRevealPath(pathStr) {{{1
 function! s:findAndRevealPath(pathStr)
     let l:pathStr = !empty(a:pathStr) ? a:pathStr : expand('%:p')
+    if !filereadable(l:pathStr)
+        let l:pathStr = fnamemodify(l:pathStr, ':h')
+    endif
 
     if empty(l:pathStr)
         call nerdtree#echoWarning('no file for the current buffer')