From 3d421b8ec5147ab46d708582290f257f0155d797 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Wed, 29 Oct 2014 19:18:28 +0000 Subject: [PATCH] use the built in fnamemodify() to make a path relative Closes #383 --- lib/nerdtree/path.vim | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 00fc7ae..ea6aa03 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -653,24 +653,14 @@ endfunction "command function! s:Path._strForEdit() let p = escape(self.str(), self._escChars()) - let cwd = getcwd() . s:Path.Slash() - "return a relative path if we can - let isRelative = 0 - if nerdtree#runningWindows() - let isRelative = stridx(tolower(p), tolower(cwd)) == 0 - else - let isRelative = stridx(p, cwd) == 0 - endif + "make it relative + let p = fnamemodify(p, ':.') - if isRelative - let p = strpart(p, strlen(cwd)) - - "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 - endif + "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 endif if p ==# ''