2008-06-17 05:03:00 -04:00
|
|
|
" ============================================================================
|
|
|
|
" File: NERD_tree.vim
|
2009-10-08 21:46:40 -04:00
|
|
|
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
|
2008-06-17 05:03:00 -04:00
|
|
|
" 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-01-04 20:08:06 -05:00
|
|
|
"
|
2007-11-02 17:23:09 -04:00
|
|
|
" SECTION: Script init stuff {{{1
|
|
|
|
"============================================================
|
|
|
|
if exists("loaded_nerd_tree")
|
|
|
|
finish
|
|
|
|
endif
|
2019-05-09 16:25:36 -04:00
|
|
|
if v:version < 703
|
2019-05-09 10:12:25 -04:00
|
|
|
echoerr "NERDTree: this plugin requires vim >= 7.3. DOWNLOAD IT! You'll thank me later!"
|
2007-11-02 17:23:09 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let loaded_nerd_tree = 1
|
2008-10-01 05:32:03 -04:00
|
|
|
|
|
|
|
"for line continuation - i.e dont want C in &cpo
|
|
|
|
let s:old_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2008-09-04 22:34:50 -04:00
|
|
|
"Function: s:initVariable() function {{{2
|
2007-11-02 17:23:09 -04:00
|
|
|
"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
|
2008-09-04 22:34:50 -04:00
|
|
|
function! s:initVariable(var, value)
|
2007-11-02 17:23:09 -04:00
|
|
|
if !exists(a:var)
|
2010-07-30 13:30:19 -04:00
|
|
|
exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'"
|
2007-11-02 17:23:09 -04:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
2008-06-08 20:46:53 -04:00
|
|
|
"SECTION: Init variable calls and other random constants {{{2
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeAutoCenter", 1)
|
|
|
|
call s:initVariable("g:NERDTreeAutoCenterThreshold", 3)
|
|
|
|
call s:initVariable("g:NERDTreeCaseSensitiveSort", 0)
|
2016-01-19 03:21:13 -05:00
|
|
|
call s:initVariable("g:NERDTreeNaturalSort", 0)
|
2014-06-09 06:06:59 -04:00
|
|
|
call s:initVariable("g:NERDTreeSortHiddenFirst", 1)
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeChDirMode", 0)
|
2016-04-26 04:15:08 -04:00
|
|
|
call s:initVariable("g:NERDTreeCreatePrefix", "silent")
|
2011-02-27 20:36:06 -05:00
|
|
|
call s:initVariable("g:NERDTreeMinimalUI", 0)
|
2019-02-24 18:01:12 -05:00
|
|
|
call s:initVariable("g:NERDTreeMinimalMenu", 0)
|
2007-11-02 17:23:09 -04:00
|
|
|
if !exists("g:NERDTreeIgnore")
|
|
|
|
let g:NERDTreeIgnore = ['\~$']
|
|
|
|
endif
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
|
2014-04-24 10:51:55 -04:00
|
|
|
call s:initVariable("g:NERDTreeBookmarksSort", 1)
|
2008-12-17 02:55:50 -05:00
|
|
|
call s:initVariable("g:NERDTreeHighlightCursorline", 1)
|
|
|
|
call s:initVariable("g:NERDTreeHijackNetrw", 1)
|
2017-06-10 17:07:57 -04:00
|
|
|
call s:initVariable('g:NERDTreeMarkBookmarks', 1)
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeMouseMode", 1)
|
|
|
|
call s:initVariable("g:NERDTreeNotificationThreshold", 100)
|
|
|
|
call s:initVariable("g:NERDTreeQuitOnOpen", 0)
|
2014-06-26 05:01:15 -04:00
|
|
|
call s:initVariable("g:NERDTreeRespectWildIgnore", 0)
|
2008-09-04 22:34:50 -04:00
|
|
|
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-11-25 18:29:00 -05:00
|
|
|
|
2017-10-27 03:06:51 -04:00
|
|
|
if !nerdtree#runningWindows() && !nerdtree#runningCygwin()
|
2016-10-04 17:52:12 -04:00
|
|
|
call s:initVariable("g:NERDTreeDirArrowExpandable", "▸")
|
|
|
|
call s:initVariable("g:NERDTreeDirArrowCollapsible", "▾")
|
2015-11-25 18:29:00 -05:00
|
|
|
else
|
|
|
|
call s:initVariable("g:NERDTreeDirArrowExpandable", "+")
|
|
|
|
call s:initVariable("g:NERDTreeDirArrowCollapsible", "~")
|
|
|
|
endif
|
2019-04-22 15:58:06 -04:00
|
|
|
|
2013-04-22 11:35:15 -04:00
|
|
|
call s:initVariable("g:NERDTreeCascadeOpenSingleChildDir", 1)
|
2016-03-05 12:20:04 -05:00
|
|
|
call s:initVariable("g:NERDTreeCascadeSingleChildDir", 1)
|
2007-11-02 17:23:09 -04:00
|
|
|
|
|
|
|
if !exists("g:NERDTreeSortOrder")
|
|
|
|
let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$']
|
|
|
|
endif
|
2018-07-27 08:46:50 -04:00
|
|
|
let g:NERDTreeOldSortOrder = []
|
2007-11-02 17:23:09 -04:00
|
|
|
|
2016-02-26 20:57:40 -05:00
|
|
|
call s:initVariable("g:NERDTreeGlyphReadOnly", "RO")
|
|
|
|
|
2019-03-07 08:24:17 -05:00
|
|
|
if has("conceal")
|
|
|
|
call s:initVariable("g:NERDTreeNodeDelimiter", "\x07")
|
|
|
|
elseif (g:NERDTreeDirArrowExpandable == "\u00a0" || g:NERDTreeDirArrowCollapsible == "\u00a0")
|
|
|
|
call s:initVariable("g:NERDTreeNodeDelimiter", "\u00b7")
|
|
|
|
else
|
|
|
|
call s:initVariable("g:NERDTreeNodeDelimiter", "\u00a0")
|
|
|
|
endif
|
Support unusual characters in file and directory names (#868)
* Use a delimiter in node to separate file/dir name from the rest.
* Switch warning message to use nerdtree#deprecated function.
* Compress the space between the tree symbols and the node.
* Include the delimiter when calculating indent or getting filename.
* Don't need to strip leading delimiter. It will already be gone.
* Simplify the way the delimiter is being used.
I don't know what I was thinking. The delimiter doesn't need to be used
to separate every indicator on the node's text, ie.
Bad: Tree|GenericFlags|Filename|ExecutableFlag|Link|ReadonlyFlag
Better: Tree GenericFlags|Filename|ExecutableFlag Link ReadonlyFlag
This was unnecessary, given that we're only interested in the filename.
So, just one pair of delimiters is all we need. That greatly simplifies
the _stripMarkup function, and restores a bunch of other statements to
what they already are in the master branch.
* Add syntax highlighting to conceal the delimiter
* Put a if has("conceal") check around the syntax statement using it.
* Make concealment work correctly for LinkFile and readonly files.
* Use highlight Ignore if conceal isn't available.
This is probably the best we can do, especially if some other character
must be used in place of nbsp.
* Make the regex better match the original, but more compact.
It was allowing 2+ spaces, instead of only 1+.
* Fix the syntax highlighing of delimiters around NERDTreeExecFile.
* Bug fix: Parse . and .. from path string with trailing slash.
* Fix unresponsive cascaded directories.
Using ':' as a more visible delimiter, when directories are cascaded,
the line appears in NERDTree like so:
▾ :lib/::nerdtree/:
Before this commit, the s:UI._stripMarkup function was leaving the
internal delimiters in place (lib/::nerdtree/). Now they are removed,
resulting in a valid path (lib/nerdtree/).
* Use .= to shorten statement. Use clearer substitutes to get node name.
* Remove node delimiters that terminate the line.
* If flags are needed after the node name, then put another delimiter
before them.
* When joining directory nodes for cascaded display, strip off the
delimiter from the child node(s).
* Remove the unnecessary substitution of doubled intermediate
delimiters, since they're not in there anymore.
* DRY up the addition of the 2nd delimiter, and use only 1 for all tags.
2018-10-24 22:41:13 -04:00
|
|
|
|
2009-09-01 01:15:48 -04:00
|
|
|
if !exists('g:NERDTreeStatusline')
|
2009-09-15 03:57:08 -04:00
|
|
|
|
|
|
|
"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-11-16 06:28:24 -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():''}"
|
2009-09-15 03:57:08 -04:00
|
|
|
|
2009-09-01 01:15:48 -04:00
|
|
|
endif
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeWinPos", "left")
|
|
|
|
call s:initVariable("g:NERDTreeWinSize", 31)
|
2007-11-02 17:23:09 -04:00
|
|
|
|
2008-06-08 20:46:53 -04:00
|
|
|
"init the shell commands that will be used to copy nodes, and remove dir trees
|
2007-11-02 17:23:09 -04:00
|
|
|
"
|
|
|
|
"Note: the space after the command is important
|
2013-01-04 20:08:06 -05:00
|
|
|
if nerdtree#runningWindows()
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeRemoveDirCmd", 'rmdir /s /q ')
|
2013-01-23 03:23:56 -05:00
|
|
|
call s:initVariable("g:NERDTreeCopyDirCmd", 'xcopy /s /e /i /y /q ')
|
|
|
|
call s:initVariable("g:NERDTreeCopyFileCmd", 'copy /y ')
|
2007-11-02 17:23:09 -04:00
|
|
|
else
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeRemoveDirCmd", 'rm -rf ')
|
|
|
|
call s:initVariable("g:NERDTreeCopyCmd", 'cp -r ')
|
2007-11-02 17:23:09 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2008-06-08 20:46:53 -04:00
|
|
|
"SECTION: Init variable calls for key mappings {{{2
|
2019-07-01 22:13:20 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapCustomOpen", "<CR>")
|
2008-09-04 22:34:50 -04:00
|
|
|
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")
|
2009-07-19 01:21:57 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapMenu", "m")
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapHelp", "?")
|
|
|
|
call s:initVariable("g:NERDTreeMapJumpFirstChild", "K")
|
|
|
|
call s:initVariable("g:NERDTreeMapJumpLastChild", "J")
|
2012-01-26 18:59:07 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapJumpNextSibling", "<C-j>")
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapJumpParent", "p")
|
2012-01-26 18:59:07 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapJumpPrevSibling", "<C-k>")
|
2008-09-04 22:34:50 -04:00
|
|
|
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")
|
2008-12-17 05:28:20 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapOpenSplit", "i")
|
2009-01-08 15:19:44 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapOpenVSplit", "s")
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapPreview", "g" . NERDTreeMapActivateNode)
|
|
|
|
call s:initVariable("g:NERDTreeMapPreviewSplit", "g" . NERDTreeMapOpenSplit)
|
2009-01-08 15:19:44 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapPreviewVSplit", "g" . NERDTreeMapOpenVSplit)
|
2008-09-04 22:34:50 -04:00
|
|
|
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")
|
2008-12-26 17:34:02 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapToggleHidden", "I")
|
2009-08-09 05:29:28 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapToggleZoom", "A")
|
2008-09-04 22:34:50 -04:00
|
|
|
call s:initVariable("g:NERDTreeMapUpdir", "u")
|
|
|
|
call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U")
|
2012-11-04 12:23:41 -05:00
|
|
|
call s:initVariable("g:NERDTreeMapCWD", "CD")
|
2018-11-29 09:17:39 -05:00
|
|
|
call s:initVariable("g:NERDTreeMenuDown", "j")
|
|
|
|
call s:initVariable("g:NERDTreeMenuUp", "k")
|
2007-11-02 17:23:09 -04:00
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
"SECTION: Load class files{{{2
|
2013-04-13 15:32:25 -04:00
|
|
|
call nerdtree#loadClassFiles()
|
2008-12-23 06:57:01 -05:00
|
|
|
|
2007-11-02 17:23:09 -04:00
|
|
|
" SECTION: Commands {{{1
|
|
|
|
"============================================================
|
2014-07-07 15:12:05 -04:00
|
|
|
call nerdtree#ui_glue#setupCommands()
|
|
|
|
|
2007-11-02 17:23:09 -04:00
|
|
|
" SECTION: Auto commands {{{1
|
|
|
|
"============================================================
|
2008-12-17 02:24:08 -05:00
|
|
|
augroup NERDTree
|
|
|
|
"Save the cursor position whenever we close the nerd tree
|
2015-05-04 15:25:03 -04:00
|
|
|
exec "autocmd BufLeave ". g:NERDTreeCreator.BufNamePrefix() ."* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif"
|
2011-08-05 10:42:41 -04:00
|
|
|
|
2011-08-30 07:03:49 -04:00
|
|
|
"disallow insert mode in the NERDTree
|
2013-01-09 04:48:16 -05:00
|
|
|
exec "autocmd BufEnter ". g:NERDTreeCreator.BufNamePrefix() ."* stopinsert"
|
2008-12-17 02:24:08 -05:00
|
|
|
augroup END
|
2007-11-02 17:23:09 -04:00
|
|
|
|
2008-12-17 02:55:50 -05:00
|
|
|
if g:NERDTreeHijackNetrw
|
|
|
|
augroup NERDTreeHijackNetrw
|
2008-12-17 05:31:59 -05:00
|
|
|
autocmd VimEnter * silent! autocmd! FileExplorer
|
2013-01-04 20:08:06 -05:00
|
|
|
au BufEnter,VimEnter * call nerdtree#checkForBrowse(expand("<amatch>"))
|
2008-12-17 02:55:50 -05:00
|
|
|
augroup END
|
|
|
|
endif
|
2008-12-13 01:32:35 -05:00
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
" SECTION: Public API {{{1
|
2008-06-28 08:23:02 -04:00
|
|
|
"============================================================
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeAddMenuItem(options)
|
|
|
|
call g:NERDTreeMenuItem.Create(a:options)
|
2008-07-13 00:38:52 -04:00
|
|
|
endfunction
|
2008-06-28 08:33:25 -04:00
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeAddMenuSeparator(...)
|
2012-01-08 12:24:30 -05:00
|
|
|
let opts = a:0 ? a:1 : {}
|
2013-01-04 20:08:06 -05:00
|
|
|
call g:NERDTreeMenuItem.CreateSeparator(opts)
|
2009-08-21 09:25:18 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeAddSubmenu(options)
|
|
|
|
return g:NERDTreeMenuItem.Create(a:options)
|
2009-08-18 10:05:02 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeAddKeyMap(options)
|
|
|
|
call g:NERDTreeKeyMap.Create(a:options)
|
2009-07-17 09:04:40 -04:00
|
|
|
endfunction
|
2008-06-28 08:23:02 -04:00
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeRender()
|
|
|
|
call nerdtree#renderView()
|
2007-11-02 17:23:09 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeFocus()
|
2015-05-02 09:44:32 -04:00
|
|
|
if g:NERDTree.IsOpen()
|
2015-05-02 10:24:59 -04:00
|
|
|
call g:NERDTree.CursorToTreeWin()
|
2011-07-08 15:10:13 -04:00
|
|
|
else
|
2015-11-14 06:50:01 -05:00
|
|
|
call g:NERDTreeCreator.ToggleTabTree("")
|
2009-01-05 19:31:17 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
function! NERDTreeCWD()
|
2018-09-10 08:46:42 -04:00
|
|
|
|
2018-09-10 09:00:05 -04:00
|
|
|
if empty(getcwd())
|
|
|
|
call nerdtree#echoWarning('current directory does not exist')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2018-09-10 08:46:42 -04:00
|
|
|
try
|
|
|
|
let l:cwdPath = g:NERDTreePath.New(getcwd())
|
|
|
|
catch /^NERDTree.InvalidArgumentsError/
|
|
|
|
call nerdtree#echoWarning('current directory does not exist')
|
|
|
|
return
|
|
|
|
endtry
|
|
|
|
|
2013-01-04 20:08:06 -05:00
|
|
|
call NERDTreeFocus()
|
2018-09-10 06:57:39 -04:00
|
|
|
|
|
|
|
if b:NERDTree.root.path.equals(l:cwdPath)
|
|
|
|
return
|
2018-08-22 17:01:08 -04:00
|
|
|
endif
|
2018-09-10 06:57:39 -04:00
|
|
|
|
|
|
|
let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree)
|
|
|
|
call b:NERDTree.changeRoot(l:newRoot)
|
2018-09-10 08:52:43 -04:00
|
|
|
normal! ^
|
2007-11-02 17:23:09 -04:00
|
|
|
endfunction
|
2015-05-02 17:20:59 -04:00
|
|
|
|
|
|
|
function! NERDTreeAddPathFilter(callback)
|
|
|
|
call g:NERDTree.AddPathFilter(a:callback)
|
|
|
|
endfunction
|
|
|
|
|
2012-01-06 10:05:47 -05:00
|
|
|
" SECTION: Post Source Actions {{{1
|
2013-01-04 20:08:06 -05:00
|
|
|
call nerdtree#postSourceActions()
|
2008-10-01 05:32:03 -04:00
|
|
|
|
|
|
|
"reset &cpo back to users setting
|
|
|
|
let &cpo = s:old_cpo
|
|
|
|
|
2008-06-08 01:34:22 -04:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|