Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed a bunch of common annoyances:

* NERDTree only opens up when opening a directory, not a file
* NERDTree behaves properly when doing: gvim /foo/bar
  * gvim behaves like gvim .
  * gvim some_file does not open NERDTree
* rm and touch update NERDTree without closing all open
  nodes, and also flushes CommandT
  • Loading branch information...
commit 0eb80f3be9c31a9bf6d472ca14de264aad8caa8a 1 parent b4731dd
Yehuda Katz authored

Showing 1 changed file with 36 additions and 17 deletions. Show diff stats Hide diff stats

  1. 53  gvimrc
53  gvimrc
@@ -31,35 +31,47 @@ function StartTerm()
31 31
 endfunction
32 32
 
33 33
 " Project Tree
34  
-autocmd VimEnter * NERDTree
35  
-autocmd VimEnter * wincmd p
36 34
 autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
37 35
 
38  
-" Disable netrw's autocmd, since we're ALWAYS using NERDTree
39  
-runtime plugin/netRwPlugin.vim
40  
-augroup FileExplorer
41  
-  au!
42  
-augroup END
43  
-
44  
-let g:NERDTreeHijackNetrw = 0
45 36
 
46 37
 " If the parameter is a directory, cd into it
47 38
 function s:CdIfDirectory(directory)
48  
-  if isdirectory(a:directory)
49  
-    call ChangeDirectory(a:directory)
  39
+  let explicitDirectory = isdirectory(a:directory)
  40
+  let directory = explicitDirectory || empty(a:directory)
  41
+
  42
+  if explicitDirectory
  43
+    exe "cd " . a:directory
  44
+  endif
  45
+
  46
+  if directory
  47
+    NERDTree
  48
+    wincmd p
  49
+    bd
50 50
   endif
51 51
 endfunction
52 52
 
53 53
 " NERDTree utility function
54  
-function s:UpdateNERDTree(stay)
  54
+function s:UpdateNERDTree(...)
  55
+  let stay = 0
  56
+
  57
+  if(exists("a:1"))
  58
+    let stay = a:1
  59
+  end
  60
+
55 61
   if exists("t:NERDTreeBufName")
56  
-    if bufwinnr(t:NERDTreeBufName) != -1
57  
-      NERDTree
58  
-      if !a:stay
  62
+    let nr = bufwinnr(t:NERDTreeBufName)
  63
+    if nr != -1
  64
+      exe nr . "wincmd w"
  65
+      exe substitute(mapcheck("R"), "<CR>", "", "")
  66
+      if !stay
59 67
         wincmd p
60 68
       end
61 69
     endif
62 70
   endif
  71
+
  72
+  if exists("CommandTFlush")
  73
+    CommandTFlush
  74
+  endif
63 75
 endfunction
64 76
 
65 77
 " Utility functions to create file commands
@@ -86,12 +98,17 @@ endfunction
86 98
 function ChangeDirectory(dir, ...)
87 99
   execute "cd " . a:dir
88 100
   let stay = exists("a:1") ? a:1 : 1
89  
-  call s:UpdateNERDTree(stay)
  101
+
  102
+  NERDTree
  103
+
  104
+  if !stay
  105
+    wincmd p
  106
+  endif
90 107
 endfunction
91 108
 
92 109
 function Touch(file)
93 110
   execute "!touch " . a:file
94  
-  call s:UpdateNERDTree(1)
  111
+  call s:UpdateNERDTree()
95 112
 endfunction
96 113
 
97 114
 function Remove(file)
@@ -103,6 +120,8 @@ function Remove(file)
103 120
   else
104 121
     execute "!rm " . a:file
105 122
   endif
  123
+
  124
+  call s:UpdateNERDTree()
106 125
 endfunction
107 126
 
108 127
 function Edit(file)

0 notes on commit 0eb80f3

Please sign in to comment.
Something went wrong with that request. Please try again.