2012-08-16 23:41:25 -04:00
|
|
|
" ============================================================================
|
|
|
|
" File: NERD_tree.vim
|
|
|
|
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
|
|
|
|
" License: This program is free software. It comes without any warranty,
|
|
|
|
" to the extent permitted by applicable law. You can redistribute
|
|
|
|
" it and/or modify it under the terms of the Do What The Fuck You
|
|
|
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
|
|
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
"
|
|
|
|
" ============================================================================
|
2013-04-13 13:45:21 -04:00
|
|
|
"
|
2012-08-16 23:41:25 -04:00
|
|
|
" SECTION: Script init stuff {{{1
|
|
|
|
"============================================================
|
2020-01-07 07:45:07 -05:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
if exists('loaded_nerd_tree')
|
2012-08-16 23:41:25 -04:00
|
|
|
finish
|
|
|
|
endif
|
2019-05-17 10:09:13 -04:00
|
|
|
if v:version < 703
|
|
|
|
echoerr "NERDTree: this plugin requires vim >= 7.3. DOWNLOAD IT! You'll thank me later!"
|
2012-08-16 23:41:25 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let loaded_nerd_tree = 1
|
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
"for line continuation - i.e dont want C in &cpoptions
|
|
|
|
let s:old_cpo = &cpoptions
|
|
|
|
set cpoptions&vim
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
"Function: s:initVariable() function {{{2
|
|
|
|
"This function is used to initialise a given variable to a given value. The
|
|
|
|
"variable is only initialised if it does not exist prior
|
|
|
|
"
|
|
|
|
"Args:
|
|
|
|
"var: the name of the var to be initialised
|
|
|
|
"value: the value to initialise var to
|
|
|
|
"
|
|
|
|
"Returns:
|
|
|
|
"1 if the var is set, 0 otherwise
|
|
|
|
function! s:initVariable(var, value)
|
|
|
|
if !exists(a:var)
|
2020-01-07 07:45:07 -05:00
|
|
|
exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", 'g') . "'"
|
2012-08-16 23:41:25 -04:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"SECTION: Init variable calls and other random constants {{{2
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeAutoCenter', 1)
|
|
|
|
call s:initVariable('g:NERDTreeAutoCenterThreshold', 3)
|
|
|
|
call s:initVariable('g:NERDTreeCaseSensitiveSort', 0)
|
|
|
|
call s:initVariable('g:NERDTreeNaturalSort', 0)
|
|
|
|
call s:initVariable('g:NERDTreeSortHiddenFirst', 1)
|
|
|
|
call s:initVariable('g:NERDTreeUseTCD', 0)
|
|
|
|
call s:initVariable('g:NERDTreeChDirMode', 0)
|
|
|
|
call s:initVariable('g:NERDTreeCreatePrefix', 'silent')
|
|
|
|
call s:initVariable('g:NERDTreeMinimalUI', 0)
|
|
|
|
call s:initVariable('g:NERDTreeMinimalMenu', 0)
|
|
|
|
if !exists('g:NERDTreeIgnore')
|
2012-08-16 23:41:25 -04:00
|
|
|
let g:NERDTreeIgnore = ['\~$']
|
|
|
|
endif
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeBookmarksFile', expand('$HOME') . '/.NERDTreeBookmarks')
|
|
|
|
call s:initVariable('g:NERDTreeBookmarksSort', 1)
|
|
|
|
call s:initVariable('g:NERDTreeHighlightCursorline', 1)
|
|
|
|
call s:initVariable('g:NERDTreeHijackNetrw', 1)
|
2017-07-06 08:57:35 -04:00
|
|
|
call s:initVariable('g:NERDTreeMarkBookmarks', 1)
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeMouseMode', 1)
|
|
|
|
call s:initVariable('g:NERDTreeNotificationThreshold', 100)
|
|
|
|
call s:initVariable('g:NERDTreeQuitOnOpen', 0)
|
|
|
|
call s:initVariable('g:NERDTreeRespectWildIgnore', 0)
|
|
|
|
call s:initVariable('g:NERDTreeShowBookmarks', 0)
|
|
|
|
call s:initVariable('g:NERDTreeShowFiles', 1)
|
|
|
|
call s:initVariable('g:NERDTreeShowHidden', 0)
|
|
|
|
call s:initVariable('g:NERDTreeShowLineNumbers', 0)
|
|
|
|
call s:initVariable('g:NERDTreeSortDirs', 1)
|
2015-12-08 08:20:04 -05:00
|
|
|
|
2017-11-24 08:54:40 -05:00
|
|
|
if !nerdtree#runningWindows() && !nerdtree#runningCygwin()
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeDirArrowExpandable', '▸')
|
|
|
|
call s:initVariable('g:NERDTreeDirArrowCollapsible', '▾')
|
2015-12-08 08:20:04 -05:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeDirArrowExpandable', '+')
|
|
|
|
call s:initVariable('g:NERDTreeDirArrowCollapsible', '~')
|
2015-12-08 08:20:04 -05:00
|
|
|
endif
|
2019-05-17 10:09:13 -04:00
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeCascadeOpenSingleChildDir', 1)
|
|
|
|
call s:initVariable('g:NERDTreeCascadeSingleChildDir', 1)
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
if !exists('g:NERDTreeSortOrder')
|
2012-08-16 23:41:25 -04:00
|
|
|
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
|
|
|
|
endif
|
2018-08-25 12:13:42 -04:00
|
|
|
let g:NERDTreeOldSortOrder = []
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeGlyphReadOnly', 'RO')
|
2016-05-14 07:57:54 -04:00
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
if has('conceal')
|
|
|
|
call s:initVariable('g:NERDTreeNodeDelimiter', "\x07")
|
|
|
|
elseif (g:NERDTreeDirArrowExpandable ==# "\u00a0" || g:NERDTreeDirArrowCollapsible ==# "\u00a0")
|
|
|
|
call s:initVariable('g:NERDTreeNodeDelimiter', "\u00b7")
|
2019-03-08 06:04:56 -05:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeNodeDelimiter', "\u00a0")
|
2019-03-08 06:04:56 -05:00
|
|
|
endif
|
2018-11-01 06:03:42 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
if !exists('g:NERDTreeStatusline')
|
|
|
|
|
|
|
|
"the exists() crap here is a hack to stop vim spazzing out when
|
|
|
|
"loading a session that was created with an open nerd tree. It spazzes
|
2015-12-08 08:20:04 -05:00
|
|
|
"because it doesnt store b:NERDTree(its a b: var, and its a hash)
|
|
|
|
let g:NERDTreeStatusline = "%{exists('b:NERDTree')?b:NERDTree.root.path.str():''}"
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
endif
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeWinPos', 'left')
|
|
|
|
call s:initVariable('g:NERDTreeWinSize', 31)
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
"init the shell commands that will be used to copy nodes, and remove dir trees
|
|
|
|
"
|
|
|
|
"Note: the space after the command is important
|
2013-04-13 13:45:21 -04:00
|
|
|
if nerdtree#runningWindows()
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeRemoveDirCmd', 'rmdir /s /q ')
|
|
|
|
call s:initVariable('g:NERDTreeCopyDirCmd', 'xcopy /s /e /i /y /q ')
|
|
|
|
call s:initVariable('g:NERDTreeCopyFileCmd', 'copy /y ')
|
2012-08-16 23:41:25 -04:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeRemoveDirCmd', 'rm -rf ')
|
|
|
|
call s:initVariable('g:NERDTreeCopyCmd', 'cp -r ')
|
2012-08-16 23:41:25 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
"SECTION: Init variable calls for key mappings {{{2
|
2020-01-07 07:45:07 -05:00
|
|
|
call s:initVariable('g:NERDTreeMapCustomOpen', '<CR>')
|
|
|
|
call s:initVariable('g:NERDTreeMapActivateNode', 'o')
|
|
|
|
call s:initVariable('g:NERDTreeMapChangeRoot', 'C')
|
|
|
|
call s:initVariable('g:NERDTreeMapChdir', 'cd')
|
|
|
|
call s:initVariable('g:NERDTreeMapCloseChildren', 'X')
|
|
|
|
call s:initVariable('g:NERDTreeMapCloseDir', 'x')
|
|
|
|
call s:initVariable('g:NERDTreeMapDeleteBookmark', 'D')
|
|
|
|
call s:initVariable('g:NERDTreeMapMenu', 'm')
|
|
|
|
call s:initVariable('g:NERDTreeMapHelp', '?')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpFirstChild', 'K')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpLastChild', 'J')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpNextSibling', '<C-j>')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpParent', 'p')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpPrevSibling', '<C-k>')
|
|
|
|
call s:initVariable('g:NERDTreeMapJumpRoot', 'P')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenExpl', 'e')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenInTab', 't')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenInTabSilent', 'T')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenRecursively', 'O')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenSplit', 'i')
|
|
|
|
call s:initVariable('g:NERDTreeMapOpenVSplit', 's')
|
|
|
|
call s:initVariable('g:NERDTreeMapPreview', 'g' . NERDTreeMapActivateNode)
|
|
|
|
call s:initVariable('g:NERDTreeMapPreviewSplit', 'g' . NERDTreeMapOpenSplit)
|
|
|
|
call s:initVariable('g:NERDTreeMapPreviewVSplit', 'g' . NERDTreeMapOpenVSplit)
|
|
|
|
call s:initVariable('g:NERDTreeMapQuit', 'q')
|
|
|
|
call s:initVariable('g:NERDTreeMapRefresh', 'r')
|
|
|
|
call s:initVariable('g:NERDTreeMapRefreshRoot', 'R')
|
|
|
|
call s:initVariable('g:NERDTreeMapToggleBookmarks', 'B')
|
|
|
|
call s:initVariable('g:NERDTreeMapToggleFiles', 'F')
|
|
|
|
call s:initVariable('g:NERDTreeMapToggleFilters', 'f')
|
|
|
|
call s:initVariable('g:NERDTreeMapToggleHidden', 'I')
|
|
|
|
call s:initVariable('g:NERDTreeMapToggleZoom', 'A')
|
|
|
|
call s:initVariable('g:NERDTreeMapUpdir', 'u')
|
|
|
|
call s:initVariable('g:NERDTreeMapUpdirKeepOpen', 'U')
|
|
|
|
call s:initVariable('g:NERDTreeMapCWD', 'CD')
|
|
|
|
call s:initVariable('g:NERDTreeMenuDown', 'j')
|
|
|
|
call s:initVariable('g:NERDTreeMenuUp', 'k')
|
2013-04-13 13:45:21 -04:00
|
|
|
|
|
|
|
"SECTION: Load class files{{{2
|
2013-04-26 12:17:22 -04:00
|
|
|
call nerdtree#loadClassFiles()
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
" SECTION: Commands {{{1
|
|
|
|
"============================================================
|
2014-08-03 18:02:51 -04:00
|
|
|
call nerdtree#ui_glue#setupCommands()
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
" SECTION: Auto commands {{{1
|
|
|
|
"============================================================
|
|
|
|
augroup NERDTree
|
|
|
|
"Save the cursor position whenever we close the nerd tree
|
2020-01-07 07:45:07 -05:00
|
|
|
exec 'autocmd BufLeave,WinLeave '. g:NERDTreeCreator.BufNamePrefix() .'* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif'
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
"disallow insert mode in the NERDTree
|
2020-01-07 07:45:07 -05:00
|
|
|
exec 'autocmd BufEnter,WinEnter '. g:NERDTreeCreator.BufNamePrefix() .'* stopinsert'
|
2012-08-16 23:41:25 -04:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
if g:NERDTreeHijackNetrw
|
|
|
|
augroup NERDTreeHijackNetrw
|
|
|
|
autocmd VimEnter * silent! autocmd! FileExplorer
|
2020-01-07 07:45:07 -05:00
|
|
|
au BufEnter,VimEnter * call nerdtree#checkForBrowse(expand('<amatch>'))
|
2012-08-16 23:41:25 -04:00
|
|
|
augroup END
|
|
|
|
endif
|
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
if g:NERDTreeChDirMode ==# 3
|
2019-11-16 10:28:42 -05:00
|
|
|
augroup NERDTreeChDirOnTabSwitch
|
|
|
|
autocmd TabEnter * if g:NERDTree.ExistsForTab()|call g:NERDTree.ForCurrentTab().getRoot().path.changeToDir()|endif
|
|
|
|
augroup END
|
|
|
|
endif
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
" SECTION: Public API {{{1
|
2012-08-16 23:41:25 -04:00
|
|
|
"============================================================
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeAddMenuItem(options)
|
|
|
|
call g:NERDTreeMenuItem.Create(a:options)
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeAddMenuSeparator(...)
|
2012-08-16 23:41:25 -04:00
|
|
|
let opts = a:0 ? a:1 : {}
|
2013-04-13 13:45:21 -04:00
|
|
|
call g:NERDTreeMenuItem.CreateSeparator(opts)
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeAddSubmenu(options)
|
|
|
|
return g:NERDTreeMenuItem.Create(a:options)
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeAddKeyMap(options)
|
|
|
|
call g:NERDTreeKeyMap.Create(a:options)
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeRender()
|
|
|
|
call nerdtree#renderView()
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeFocus()
|
2015-07-13 06:22:46 -04:00
|
|
|
if g:NERDTree.IsOpen()
|
2020-05-10 10:24:38 -04:00
|
|
|
call g:NERDTree.CursorToTreeWin(0)
|
2012-08-16 23:41:25 -04:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
call g:NERDTreeCreator.ToggleTabTree('')
|
2012-08-16 23:41:25 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
function! NERDTreeCWD()
|
2018-09-24 20:40:17 -04:00
|
|
|
|
|
|
|
if empty(getcwd())
|
|
|
|
call nerdtree#echoWarning('current directory does not exist')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
try
|
|
|
|
let l:cwdPath = g:NERDTreePath.New(getcwd())
|
|
|
|
catch /^NERDTree.InvalidArgumentsError/
|
|
|
|
call nerdtree#echoWarning('current directory does not exist')
|
|
|
|
return
|
|
|
|
endtry
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
call NERDTreeFocus()
|
2018-09-24 20:40:17 -04:00
|
|
|
|
|
|
|
if b:NERDTree.root.path.equals(l:cwdPath)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree)
|
|
|
|
call b:NERDTree.changeRoot(l:newRoot)
|
|
|
|
normal! ^
|
2012-08-16 23:41:25 -04:00
|
|
|
endfunction
|
2015-07-13 06:22:46 -04:00
|
|
|
|
|
|
|
function! NERDTreeAddPathFilter(callback)
|
|
|
|
call g:NERDTree.AddPathFilter(a:callback)
|
|
|
|
endfunction
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
" SECTION: Post Source Actions {{{1
|
2013-04-13 13:45:21 -04:00
|
|
|
call nerdtree#postSourceActions()
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
"reset &cpoptions back to users setting
|
|
|
|
let &cpoptions = s:old_cpo
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|