NERD_tree.vim 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. " ============================================================================
  2. " File: NERD_tree.vim
  3. " Description: vim global plugin that provides a nice tree explorer
  4. " Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
  5. " Last Change: 28 December, 2011
  6. " License: This program is free software. It comes without any warranty,
  7. " to the extent permitted by applicable law. You can redistribute
  8. " it and/or modify it under the terms of the Do What The Fuck You
  9. " Want To Public License, Version 2, as published by Sam Hocevar.
  10. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  11. "
  12. " ============================================================================
  13. "
  14. " SECTION: Script init stuff {{{1
  15. "============================================================
  16. if exists("loaded_nerd_tree")
  17. finish
  18. endif
  19. if v:version < 700
  20. echoerr "NERDTree: this plugin requires vim >= 7. DOWNLOAD IT! You'll thank me later!"
  21. finish
  22. endif
  23. let loaded_nerd_tree = 1
  24. "for line continuation - i.e dont want C in &cpo
  25. let s:old_cpo = &cpo
  26. set cpo&vim
  27. "Function: s:initVariable() function {{{2
  28. "This function is used to initialise a given variable to a given value. The
  29. "variable is only initialised if it does not exist prior
  30. "
  31. "Args:
  32. "var: the name of the var to be initialised
  33. "value: the value to initialise var to
  34. "
  35. "Returns:
  36. "1 if the var is set, 0 otherwise
  37. function! s:initVariable(var, value)
  38. if !exists(a:var)
  39. exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'"
  40. return 1
  41. endif
  42. return 0
  43. endfunction
  44. "SECTION: Init variable calls and other random constants {{{2
  45. call s:initVariable("g:NERDTreeAutoCenter", 1)
  46. call s:initVariable("g:NERDTreeAutoCenterThreshold", 3)
  47. call s:initVariable("g:NERDTreeCaseSensitiveSort", 0)
  48. call s:initVariable("g:NERDTreeSortHiddenFirst", 1)
  49. call s:initVariable("g:NERDTreeChDirMode", 0)
  50. call s:initVariable("g:NERDTreeMinimalUI", 0)
  51. if !exists("g:NERDTreeIgnore")
  52. let g:NERDTreeIgnore = ['\~$']
  53. endif
  54. call s:initVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
  55. call s:initVariable("g:NERDTreeBookmarksSort", 1)
  56. call s:initVariable("g:NERDTreeHighlightCursorline", 1)
  57. call s:initVariable("g:NERDTreeHijackNetrw", 1)
  58. call s:initVariable("g:NERDTreeMouseMode", 1)
  59. call s:initVariable("g:NERDTreeNotificationThreshold", 100)
  60. call s:initVariable("g:NERDTreeQuitOnOpen", 0)
  61. call s:initVariable("g:NERDTreeRespectWildIgnore", 0)
  62. call s:initVariable("g:NERDTreeShowBookmarks", 0)
  63. call s:initVariable("g:NERDTreeShowFiles", 1)
  64. call s:initVariable("g:NERDTreeShowHidden", 0)
  65. call s:initVariable("g:NERDTreeShowLineNumbers", 0)
  66. call s:initVariable("g:NERDTreeSortDirs", 1)
  67. call s:initVariable("g:NERDTreeDirArrows", !nerdtree#runningWindows())
  68. call s:initVariable("g:NERDTreeCascadeOpenSingleChildDir", 1)
  69. if !exists("g:NERDTreeSortOrder")
  70. let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
  71. else
  72. "if there isnt a * in the sort sequence then add one
  73. if count(g:NERDTreeSortOrder, '*') < 1
  74. call add(g:NERDTreeSortOrder, '*')
  75. endif
  76. endif
  77. if !exists('g:NERDTreeStatusline')
  78. "the exists() crap here is a hack to stop vim spazzing out when
  79. "loading a session that was created with an open nerd tree. It spazzes
  80. "because it doesnt store b:NERDTreeRoot (its a b: var, and its a hash)
  81. let g:NERDTreeStatusline = "%{exists('b:NERDTreeRoot')?b:NERDTreeRoot.path.str():''}"
  82. endif
  83. call s:initVariable("g:NERDTreeWinPos", "left")
  84. call s:initVariable("g:NERDTreeWinSize", 31)
  85. "init the shell commands that will be used to copy nodes, and remove dir trees
  86. "
  87. "Note: the space after the command is important
  88. if nerdtree#runningWindows()
  89. call s:initVariable("g:NERDTreeRemoveDirCmd", 'rmdir /s /q ')
  90. else
  91. call s:initVariable("g:NERDTreeRemoveDirCmd", 'rm -rf ')
  92. call s:initVariable("g:NERDTreeCopyCmd", 'cp -r ')
  93. endif
  94. "SECTION: Init variable calls for key mappings {{{2
  95. call s:initVariable("g:NERDTreeMapActivateNode", "o")
  96. call s:initVariable("g:NERDTreeMapChangeRoot", "C")
  97. call s:initVariable("g:NERDTreeMapChdir", "cd")
  98. call s:initVariable("g:NERDTreeMapCloseChildren", "X")
  99. call s:initVariable("g:NERDTreeMapCloseDir", "x")
  100. call s:initVariable("g:NERDTreeMapDeleteBookmark", "D")
  101. call s:initVariable("g:NERDTreeMapMenu", "m")
  102. call s:initVariable("g:NERDTreeMapHelp", "?")
  103. call s:initVariable("g:NERDTreeMapJumpFirstChild", "K")
  104. call s:initVariable("g:NERDTreeMapJumpLastChild", "J")
  105. call s:initVariable("g:NERDTreeMapJumpNextSibling", "<C-j>")
  106. call s:initVariable("g:NERDTreeMapJumpParent", "p")
  107. call s:initVariable("g:NERDTreeMapJumpPrevSibling", "<C-k>")
  108. call s:initVariable("g:NERDTreeMapJumpRoot", "P")
  109. call s:initVariable("g:NERDTreeMapOpenExpl", "e")
  110. call s:initVariable("g:NERDTreeMapOpenInTab", "t")
  111. call s:initVariable("g:NERDTreeMapOpenInTabSilent", "T")
  112. call s:initVariable("g:NERDTreeMapOpenRecursively", "O")
  113. call s:initVariable("g:NERDTreeMapOpenSplit", "i")
  114. call s:initVariable("g:NERDTreeMapOpenVSplit", "s")
  115. call s:initVariable("g:NERDTreeMapPreview", "g" . NERDTreeMapActivateNode)
  116. call s:initVariable("g:NERDTreeMapPreviewSplit", "g" . NERDTreeMapOpenSplit)
  117. call s:initVariable("g:NERDTreeMapPreviewVSplit", "g" . NERDTreeMapOpenVSplit)
  118. call s:initVariable("g:NERDTreeMapQuit", "q")
  119. call s:initVariable("g:NERDTreeMapRefresh", "r")
  120. call s:initVariable("g:NERDTreeMapRefreshRoot", "R")
  121. call s:initVariable("g:NERDTreeMapToggleBookmarks", "B")
  122. call s:initVariable("g:NERDTreeMapToggleFiles", "F")
  123. call s:initVariable("g:NERDTreeMapToggleFilters", "f")
  124. call s:initVariable("g:NERDTreeMapToggleHidden", "I")
  125. call s:initVariable("g:NERDTreeMapToggleZoom", "A")
  126. call s:initVariable("g:NERDTreeMapUpdir", "u")
  127. call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U")
  128. call s:initVariable("g:NERDTreeMapCWD", "CD")
  129. "SECTION: Load class files{{{2
  130. call nerdtree#loadClassFiles()
  131. " SECTION: Commands {{{1
  132. "============================================================
  133. call nerdtree#ui_glue#setupCommands()
  134. " SECTION: Auto commands {{{1
  135. "============================================================
  136. augroup NERDTree
  137. "Save the cursor position whenever we close the nerd tree
  138. exec "autocmd BufLeave ". g:NERDTreeCreator.BufNamePrefix() ."* call b:NERDTree.ui.saveScreenState()"
  139. "disallow insert mode in the NERDTree
  140. exec "autocmd BufEnter ". g:NERDTreeCreator.BufNamePrefix() ."* stopinsert"
  141. augroup END
  142. if g:NERDTreeHijackNetrw
  143. augroup NERDTreeHijackNetrw
  144. autocmd VimEnter * silent! autocmd! FileExplorer
  145. au BufEnter,VimEnter * call nerdtree#checkForBrowse(expand("<amatch>"))
  146. augroup END
  147. endif
  148. " SECTION: Public API {{{1
  149. "============================================================
  150. function! NERDTreeAddMenuItem(options)
  151. call g:NERDTreeMenuItem.Create(a:options)
  152. endfunction
  153. function! NERDTreeAddMenuSeparator(...)
  154. let opts = a:0 ? a:1 : {}
  155. call g:NERDTreeMenuItem.CreateSeparator(opts)
  156. endfunction
  157. function! NERDTreeAddSubmenu(options)
  158. return g:NERDTreeMenuItem.Create(a:options)
  159. endfunction
  160. function! NERDTreeAddKeyMap(options)
  161. call g:NERDTreeKeyMap.Create(a:options)
  162. endfunction
  163. function! NERDTreeRender()
  164. call nerdtree#renderView()
  165. endfunction
  166. function! NERDTreeFocus()
  167. if nerdtree#isTreeOpen()
  168. call nerdtree#putCursorInTreeWin()
  169. else
  170. call g:NERDTreeCreator.TogglePrimary("")
  171. endif
  172. endfunction
  173. function! NERDTreeCWD()
  174. call NERDTreeFocus()
  175. call nerdtree#ui_glue#chRootCwd()
  176. endfunction
  177. " SECTION: Post Source Actions {{{1
  178. call nerdtree#postSourceActions()
  179. "reset &cpo back to users setting
  180. let &cpo = s:old_cpo
  181. " vim: set sw=4 sts=4 et fdm=marker: