From a32a55e8d98413459aa309176501b97b3f8a350e Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 11 Aug 2017 10:09:18 -0400 Subject: [PATCH] Rewrite the "Path._strForEdit()" method This method used the brittle "Path._escChars()" method to do its work. This created problems when 'shellslash' was in use on Windows because excessive escape characters (i.e., backslashes!) are interpreted by Vim as additional path separators. The above problem made it impossible to edit files with weird names using the NERDTree on Windows with 'shellslash' set. For example, '+' should be escaped with ":edit", but '(' should not. So, when escaping '(', Vim on Windows correctly sees the start of a new directory in the path. This was reported in five issues which may be read for further details and commentary. Fixes #398, fixes #474, fixes #653, fixes #674, and fixes #733. --- lib/nerdtree/path.vim | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 2082eb5..3e7c913 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -726,22 +726,23 @@ endfunction " Return a string representation of this Path that is suitable for use as an " argument to Vim's internal ":edit" command. function! s:Path._strForEdit() - let p = escape(self.str(), self._escChars()) - "make it relative - let p = fnamemodify(p, ':.') + " Make the path relative to the current working directory, if possible. + let l:result = fnamemodify(self.str(), ':.') - "handle the edge case where the file begins with a + (vim interprets - "the +foo in `:e +foo` as an option to :edit) - if p[0] == "+" - let p = '\' . p + " On Windows, the drive letter may be removed by "fnamemodify()". Add it + " back, if necessary. + if nerdtree#runningWindows() && l:result[0] == s:Path.Slash() + let l:result = self.drive . l:result endif - if p ==# '' - let p = '.' + let l:result = fnameescape(l:result) + + if empty(l:result) + let l:result = '.' endif - return p + return l:result endfunction " FUNCTION: Path._strForGlob() {{{1