mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-08 19:33:50 -05:00
Compare commits
78 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95ee07c9d3 | ||
|
|
b58ccce913 | ||
|
|
b60bcb6cb2 | ||
|
|
f7e8c453ea | ||
|
|
58ccd230fa | ||
|
|
866df769b5 | ||
|
|
bd3b03fd79 | ||
|
|
9030ff0312 | ||
|
|
5172efc976 | ||
|
|
b252a1250a | ||
|
|
dae5c93fec | ||
|
|
004b4fc9dd | ||
|
|
7614f745ae | ||
|
|
585b5f1579 | ||
|
|
bc41c51f93 | ||
|
|
0888f6c011 | ||
|
|
df8f132d6e | ||
|
|
d7a319c3a6 | ||
|
|
5a45ea08c4 | ||
|
|
ec7e013150 | ||
|
|
5b35d0bb31 | ||
|
|
40ccf3cd45 | ||
|
|
1b17f945a3 | ||
|
|
421431b5df | ||
|
|
26983f1921 | ||
|
|
1571274aec | ||
|
|
a111af5361 | ||
|
|
64514e3ceb | ||
|
|
bcc690a141 | ||
|
|
397dee5cb1 | ||
|
|
dbb0677749 | ||
|
|
0fed73d83a | ||
|
|
3a437b402a | ||
|
|
1d9564db54 | ||
|
|
c63e183acf | ||
|
|
6334e99192 | ||
|
|
776aeef26f | ||
|
|
1d6516b96d | ||
|
|
995f7faec3 | ||
|
|
140deac284 | ||
|
|
6e24eed04a | ||
|
|
82c1fece9f | ||
|
|
371379a860 | ||
|
|
0a91f3511e | ||
|
|
192424429d | ||
|
|
3092355648 | ||
|
|
ae50662943 | ||
|
|
8529b6f0e3 | ||
|
|
d718f1098c | ||
|
|
0501fc825c | ||
|
|
05ce3ab896 | ||
|
|
642c2b76fc | ||
|
|
6b7760e6e4 | ||
|
|
5cafc7018d | ||
|
|
332756282a | ||
|
|
bcc1180510 | ||
|
|
2ecd6ebd63 | ||
|
|
5a4ef66db2 | ||
|
|
a537e1535c | ||
|
|
44e8534f1f | ||
|
|
c108a19881 | ||
|
|
5685fa7af4 | ||
|
|
990706b725 | ||
|
|
6e60ecfee1 | ||
|
|
219d16f61a | ||
|
|
5fd7441dbe | ||
|
|
a5f86e1a8f | ||
|
|
782e60efc9 | ||
|
|
7b26dac959 | ||
|
|
600f2cac14 | ||
|
|
fb3c4f9212 | ||
|
|
24c1f6beab | ||
|
|
3e507620fe | ||
|
|
a520080cc3 | ||
|
|
b747086137 | ||
|
|
7a1dbcbdb0 | ||
|
|
ce9fece626 | ||
|
|
90fd47bd00 |
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
omg its ... ~
|
||||
|
||||
________ ________ _ ____________ ____ __________ ____________~
|
||||
/_ __/ / / / ____/ / | / / ____/ __ \/ __ \ /_ __/ __ \/ ____/ ____/~
|
||||
@@ -21,9 +21,10 @@ CONTENTS *NERDTree-contents*
|
||||
|
||||
1.Intro...................................|NERDTree|
|
||||
2.Functionality provided..................|NERDTreeFunctionality|
|
||||
2.1 Commands..........................|NERDTreeCommands|
|
||||
2.2 NERD tree mappings................|NERDTreeMappings|
|
||||
2.3 The filesystem menu...............|NERDTreeFilesysMenu|
|
||||
2.1 Global commands...................|NERDTreeGlobalCommands|
|
||||
2.2 Bookmark commands.................|NERDTreeBookmarkCommands|
|
||||
2.3 NERD tree mappings................|NERDTreeMappings|
|
||||
2.4 The filesystem menu...............|NERDTreeFilesysMenu|
|
||||
3.Options.................................|NERDTreeOptions|
|
||||
3.1 Option summary....................|NERDTreeOptionSummary|
|
||||
3.2 Option details....................|NERDTreeOptionDetails|
|
||||
@@ -57,6 +58,7 @@ The following features and functionality are provided by the NERD tree:
|
||||
* Mappings to change the current root of the tree
|
||||
* Mappings to navigate around the tree
|
||||
* ...
|
||||
* Directories and files can be bookmarked.
|
||||
* Most NERD tree navigation can also be done with the mouse
|
||||
* Dynamic customisation of tree content
|
||||
* custom file filters to prevent e.g. vim backup files being displayed
|
||||
@@ -82,25 +84,69 @@ The following features and functionality are provided by the NERD tree:
|
||||
2. Functionality provided *NERDTreeFunctionality*
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.1. Commands *NERDTreeCommands*
|
||||
2.1. Global Commands *NERDTreeGlobalCommands*
|
||||
|
||||
:NERDTree [start-directory] *:NERDTree*
|
||||
Opens a fresh NERD tree in [start-directory] or the current
|
||||
directory if [start-directory] isn't specified.
|
||||
For example: >
|
||||
:NERDTree [<start-directory> | <bookmark>] *:NERDTree*
|
||||
Opens a fresh NERD tree. The root of the tree depends on the argument
|
||||
given. There are 3 cases: If no argument is given, the current directory
|
||||
will be used. If a directory is given, that will be used. If a bookmark
|
||||
name is given, the corresponding directory will be used. For example: >
|
||||
:NERDTree /home/marty/vim7/src
|
||||
< will open a NERD tree in /home/marty/vim7/src.
|
||||
:NERDTree foo (foo is the name of a bookmark)
|
||||
<
|
||||
:NERDTreeFromBookmark <bookmark> *:NERDTreeFromBookmark*
|
||||
Opens a fresh NERD tree with the root initialized to the dir for
|
||||
<bookmark>. This only reason to use this command over :NERDTree is for
|
||||
the completion (which is for bookmarks rather than directories).
|
||||
|
||||
:NERDTreeToggle [start-directory] *:NERDTreeToggle*
|
||||
If a NERD tree already exists for this tab, it is reopened and
|
||||
rendered again. If no NERD tree exists for this tab then this
|
||||
command acts the same as the |:NERDTree| command.
|
||||
:NERDTreeToggle [<start-directory> | <bookmark>] *:NERDTreeToggle*
|
||||
If a NERD tree already exists for this tab, it is reopened and rendered
|
||||
again. If no NERD tree exists for this tab then this command acts the
|
||||
same as the |:NERDTree| command.
|
||||
|
||||
:NERDTreeClose
|
||||
Close the NERD tree in this tab.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.2. NERD tree Mappings *NERDTreeMappings*
|
||||
2.2. Bookmark Commands *NERDTreeBookmarkCommands*
|
||||
|
||||
Bookmarks in the NERD tree are a way to tag files or directories of interest.
|
||||
For example, you could use bookmarks to tag all of your project directories.
|
||||
See also |:NERDTree| and |:NERDTreeFromBookmark|.
|
||||
|
||||
Note that the following commands are only available in the NERD tree buffer.
|
||||
|
||||
:Bookmark <name>
|
||||
Bookmark the current node as <name>. If there is already a <name>
|
||||
bookmark, it is overwritten. <name> must consist of alphanumeric
|
||||
characters and underscores.
|
||||
|
||||
:BookmarkToRoot <bookmark>
|
||||
Make the directory corresponding to <bookmark> the new root. If a treenode
|
||||
corresponding to <bookmark> is already cached somewhere in the tree then
|
||||
the current tree will be used, otherwise a fresh tree will be opened.
|
||||
Note that if <bookmark> points to a file then its parent will be used
|
||||
instead.
|
||||
|
||||
:RevealBookmark <bookmark>
|
||||
If the node is cached under the current root then it will be revealed
|
||||
(i.e. directory nodes above it will be opened) and the cursor will be
|
||||
placed on it.
|
||||
|
||||
:OpenBookmark <bookmark>
|
||||
<bookmark> must point to a file. The file is opened as though |NERDTree-o|
|
||||
was applied. If the node is cached under the current root then it will be
|
||||
revealed and the cursor will be placed on it.
|
||||
|
||||
:ClearBookmarks [<bookmarks>]
|
||||
Remove all the given bookmarks. If no bookmarks are given then remove all
|
||||
bookmarks on the current node.
|
||||
|
||||
:ClearAllBookmarks
|
||||
Remove all bookmarks.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
2.3. NERD tree Mappings *NERDTreeMappings*
|
||||
|
||||
Default Description~ help-tag~
|
||||
Key~
|
||||
@@ -315,7 +361,8 @@ Default key: C
|
||||
Map option: NERDTreeMapChdir
|
||||
Applies to: directories.
|
||||
|
||||
Made the selected directory node the new tree root.
|
||||
Make the selected directory node the new tree root. If a file is selected, its
|
||||
parent is used.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*NERDTree-u*
|
||||
@@ -472,6 +519,8 @@ NERD tree. These options should be set in your vimrc.
|
||||
|
||||
|NERDTreeIgnore| Tells the NERD tree which files to ignore.
|
||||
|
||||
|NERDTreeBookmarksFile| Where the bookmarks are stored.
|
||||
|
||||
|NERDTreeMouseMode| Tells the NERD tree how to handle mouse
|
||||
clicks.
|
||||
|
||||
@@ -620,6 +669,13 @@ line: >
|
||||
The file filters can be turned on and off dynamically with the |NERDTree-f|
|
||||
mapping.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*NERDTreeBookmarksFile*
|
||||
Values: a path
|
||||
Default: $HOME/.NERDTreeBookmarks
|
||||
|
||||
This is where bookmarks are saved. See |NERDTreeBookmarkCommands|.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*NERDTreeMouseMode*
|
||||
Values: 1, 2 or 3.
|
||||
@@ -784,6 +840,13 @@ fridge for later ;)
|
||||
==============================================================================
|
||||
7. Changelog *NERDTreeChangelog*
|
||||
|
||||
2.10.0
|
||||
- added bookmarks, see :help NERDTreeBookmarkCommands for details. Thanks
|
||||
to Piotr Czachur for all his testing and suggestions.
|
||||
- fixed screen jumping bug with when &scrolloff != 0
|
||||
- fixed some bugs with copying nodes
|
||||
- other random fixes
|
||||
|
||||
2.9.0
|
||||
|
||||
- path handling improvements, thanks to Zhang Shuhan for heaps of
|
||||
@@ -1014,3 +1077,9 @@ NERD tree window optional.
|
||||
|
||||
Thanks to Zhang Shuhan for all of his emails and testing to help improve the
|
||||
NERD tree path handling.
|
||||
|
||||
Thanks to Cory Echols for sending a patch to add the :NERDTreeClose command and
|
||||
set the NERD tree buffers filetype to 'nerdtree'
|
||||
|
||||
Thanks to Piotr Czachur for all his suggestions and testing for the bookmarks
|
||||
feature.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
" vim global plugin that provides a nice tree explorer
|
||||
" Last Change: 17 May 2008
|
||||
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
|
||||
let s:NERD_tree_version = '2.9.0'
|
||||
let s:NERD_tree_version = '2.10.0rc1'
|
||||
|
||||
" SECTION: Script init stuff {{{1
|
||||
"============================================================
|
||||
@@ -41,6 +41,7 @@ if !exists("g:NERDTreeIgnore")
|
||||
let g:NERDTreeIgnore = ['\~$']
|
||||
endif
|
||||
call s:InitVariable("g:NERDTreeHighlightCursorline", 1)
|
||||
call s:InitVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
|
||||
call s:InitVariable("g:NERDTreeMouseMode", 1)
|
||||
call s:InitVariable("g:NERDTreeNotificationThreshold", 100)
|
||||
call s:InitVariable("g:NERDTreeShowFiles", 1)
|
||||
@@ -59,7 +60,7 @@ endif
|
||||
|
||||
"we need to use this number many times for sorting... so we calculate it only
|
||||
"once here
|
||||
let g:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
||||
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
||||
|
||||
call s:InitVariable("g:NERDTreeSplitVertical", 1)
|
||||
call s:InitVariable("g:NERDTreeWinPos", 1)
|
||||
@@ -140,10 +141,13 @@ endif
|
||||
command! -n=? -complete=dir NERDTree :call s:InitNerdTree('<args>')
|
||||
command! -n=? -complete=dir NERDTreeToggle :call s:Toggle('<args>')
|
||||
command! -n=0 NERDTreeClose :call s:CloseTreeIfOpen()
|
||||
command! -n=1 -complete=customlist,s:FindBookmarks NERDTreeFromBookmark call s:InitNerdTree('<args>')
|
||||
" SECTION: Auto commands {{{1
|
||||
"============================================================
|
||||
"Save the cursor position whenever we close the nerd tree
|
||||
exec "autocmd BufWinLeave *". s:NERDTreeWinName ."* :call <SID>SaveScreenState()"
|
||||
"cache bookmarks when vim loads
|
||||
autocmd VimEnter * call <SID>ReadBookmarks()
|
||||
|
||||
"SECTION: Classes {{{1
|
||||
"============================================================
|
||||
@@ -153,6 +157,17 @@ exec "autocmd BufWinLeave *". s:NERDTreeWinName ."* :call <SID>SaveScreenState()
|
||||
"classes.
|
||||
"============================================================
|
||||
let s:oTreeFileNode = {}
|
||||
"FUNCTION: oTreeFileNode.CacheParent {{{3
|
||||
"initializes self.parent if it isnt already
|
||||
function! s:oTreeFileNode.CacheParent() dict
|
||||
if empty(self.parent)
|
||||
let parentPath = self.path.GetParent()
|
||||
if parentPath.Equals(self.path)
|
||||
throw "NERDTree.CannotCacheParent exception: already at root"
|
||||
endif
|
||||
let self.parent = s:oTreeFileNode.New(parentPath)
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: oTreeFileNode.CompareNodes {{{3
|
||||
"This is supposed to be a class level method but i cant figure out how to
|
||||
"get func refs to work from a dict..
|
||||
@@ -165,14 +180,25 @@ function! s:CompareNodes(n1, n2)
|
||||
return a:n1.path.CompareTo(a:n2.path)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeFileNode.ClearBookmarks() {{{3
|
||||
function! s:oTreeFileNode.ClearBookmarks() dict
|
||||
let bookmarks = s:GetBookmarks()
|
||||
for i in keys(bookmarks)
|
||||
if bookmarks[i].Equals(self.path)
|
||||
call remove(bookmarks, i)
|
||||
end
|
||||
endfor
|
||||
call self.path.CacheBookmarkNames()
|
||||
endfunction
|
||||
"FUNCTION: oTreeFileNode.Copy(dest) {{{3
|
||||
function! s:oTreeFileNode.Copy(dest) dict
|
||||
call self.path.Copy(a:dest)
|
||||
let newPath = s:oPath.New(a:dest)
|
||||
let parentNode = t:NERDTreeRoot.FindNode(newPath.GetDir())
|
||||
if !empty(parentNode)
|
||||
call parentNode.Refresh()
|
||||
let parent = t:NERDTreeRoot.FindNode(newPath.GetParent())
|
||||
if !empty(parent)
|
||||
call parent.Refresh()
|
||||
endif
|
||||
return parent.FindNode(newPath)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeFileNode.Delete {{{3
|
||||
@@ -289,6 +315,23 @@ function! s:oTreeFileNode.IsRoot() dict
|
||||
return self.Equals(t:NERDTreeRoot)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeFileNode.MakeRoot() {{{3
|
||||
"Make this node the root of the tree
|
||||
function! s:oTreeFileNode.MakeRoot() dict
|
||||
if self.path.isDirectory
|
||||
let t:NERDTreeRoot = self
|
||||
else
|
||||
call self.CacheParent()
|
||||
let t:NERDTreeRoot = self.parent
|
||||
endif
|
||||
|
||||
call t:NERDTreeRoot.Open()
|
||||
|
||||
"change dir to the dir of the new root if instructed to
|
||||
if g:NERDTreeChDirMode == 2
|
||||
exec "cd " . t:NERDTreeRoot.path.StrForEditCmd()
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: oTreeFileNode.New(path) {{{3
|
||||
"Returns a new TreeNode object with the given path and parent
|
||||
"
|
||||
@@ -306,6 +349,10 @@ function! s:oTreeFileNode.New(path) dict
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeFileNode.Refresh {{{3
|
||||
function! s:oTreeFileNode.Refresh() dict
|
||||
call self.path.Refresh()
|
||||
endfunction
|
||||
"FUNCTION: oTreeFileNode.Rename {{{3
|
||||
"Calls the rename method for this nodes path obj
|
||||
function! s:oTreeFileNode.Rename(newName) dict
|
||||
@@ -659,11 +706,15 @@ function! s:oTreeDirNode.OpenRecursively2(forceOpen) dict
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeDirNode.Refresh {{{3
|
||||
unlet s:oTreeDirNode.Refresh
|
||||
function! s:oTreeDirNode.Refresh() dict
|
||||
call self.path.Refresh()
|
||||
|
||||
"if this node was ever opened, refresh its children
|
||||
if self.isOpen || !empty(self.children)
|
||||
"go thru all the files/dirs under this node
|
||||
let newChildNodes = []
|
||||
let invalidFilesFound = 0
|
||||
|
||||
"go thru all the files/dirs under this node
|
||||
let dir = self.path
|
||||
let filesStr = globpath(dir.StrForGlob(), '*') . "\n" . globpath(dir.StrForGlob(), '.*')
|
||||
let files = split(filesStr, "\n")
|
||||
@@ -675,17 +726,7 @@ function! s:oTreeDirNode.Refresh() dict
|
||||
let path = s:oPath.New(i)
|
||||
let newNode = self.GetChild(path)
|
||||
if newNode != {}
|
||||
|
||||
"if the existing node is a dir can be refreshed then
|
||||
"refresh it
|
||||
if newNode.path.isDirectory && (!empty(newNode.children) || newNode.isOpen == 1)
|
||||
call newNode.Refresh()
|
||||
|
||||
"if we have a filenode then refresh the path
|
||||
elseif newNode.path.isDirectory == 0
|
||||
call newNode.path.Refresh()
|
||||
endif
|
||||
|
||||
call add(newChildNodes, newNode)
|
||||
|
||||
"the node doesnt exist so create it
|
||||
@@ -709,6 +750,7 @@ function! s:oTreeDirNode.Refresh() dict
|
||||
if invalidFilesFound
|
||||
call s:EchoWarning("some files could not be loaded into the NERD tree")
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oTreeDirNode.RemoveChild {{{3
|
||||
@@ -771,6 +813,24 @@ endfunction
|
||||
"============================================================
|
||||
let s:oPath = {}
|
||||
let oPath = s:oPath
|
||||
"FUNCTION: oPath.BookmarkNames() {{{3
|
||||
function! s:oPath.BookmarkNames() dict
|
||||
if !exists("self.bookmarkNames")
|
||||
call self.CacheBookmarkNames()
|
||||
endif
|
||||
return self.bookmarkNames
|
||||
endfunction
|
||||
"FUNCTION: oPath.CacheBookmarkNames() {{{3
|
||||
function! s:oPath.CacheBookmarkNames() dict
|
||||
let self.bookmarkNames = []
|
||||
let bookmarks = s:GetBookmarks()
|
||||
for k in keys(bookmarks)
|
||||
if bookmarks[k].Equals(self)
|
||||
call add(self.bookmarkNames, k)
|
||||
endif
|
||||
endfor
|
||||
return self.bookmarkNames
|
||||
endfunction
|
||||
"FUNCTION: oPath.ChangeToDir() {{{3
|
||||
function! s:oPath.ChangeToDir() dict
|
||||
let dir = self.StrForCd()
|
||||
@@ -1018,7 +1078,7 @@ function! s:oPath.GetSortOrderIndex() dict
|
||||
endif
|
||||
let i = i + 1
|
||||
endwhile
|
||||
return g:NERDTreeSortStarIndex
|
||||
return s:NERDTreeSortStarIndex
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oPath.Ignore() {{{3
|
||||
@@ -1127,6 +1187,7 @@ endfunction
|
||||
"FUNCTION: oPath.Refresh() {{{3
|
||||
function! s:oPath.Refresh() dict
|
||||
call self.ReadInfoFromDisk(self.StrForOS(0))
|
||||
call self.CacheBookmarkNames()
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oPath.Rename() {{{3
|
||||
@@ -1195,6 +1256,11 @@ endfunction
|
||||
function! s:oPath.StrDisplay() dict
|
||||
let toReturn = self.GetLastPathComponent(1)
|
||||
|
||||
let bookmarks = self.BookmarkNames()
|
||||
if !empty(bookmarks)
|
||||
let toReturn .= ' {' . join(bookmarks, ',') . '}'
|
||||
endif
|
||||
|
||||
if self.isSymLink
|
||||
let toReturn .= ' -> ' . self.symLinkDest
|
||||
endif
|
||||
@@ -1269,6 +1335,15 @@ function! s:oPath.StrTrunk() dict
|
||||
return self.drive . '/' . join(self.pathSegments[0:-2], '/')
|
||||
endfunction
|
||||
|
||||
"FUNCTION: oPath.UncacheBookmark(name){{{3
|
||||
"remove the given bookmark from this paths cached bookmarks
|
||||
function! s:oPath.UncacheBookmark(name) dict
|
||||
let bookmarks = self.BookmarkNames()
|
||||
let i = index(bookmarks, a:name)
|
||||
if i != -1
|
||||
echo remove(bookmarks, i)
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: oPath.WinToUnixPath(pathstr){{{3
|
||||
"Takes in a windows path and returns the unix equiv
|
||||
"
|
||||
@@ -1303,7 +1378,15 @@ function! s:Abs(num)
|
||||
return 0 - a:num
|
||||
end
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:AbsoluteTreeRoot(){{{2
|
||||
" returns the highest cached ancestor of the current root
|
||||
function! s:AbsoluteTreeRoot()
|
||||
let currentNode = t:NERDTreeRoot
|
||||
while currentNode.parent != {}
|
||||
let currentNode = currentNode.parent
|
||||
endwhile
|
||||
return currentNode
|
||||
endfunction
|
||||
"FUNCTION: s:BufInWindows(bnum){{{2
|
||||
"[[STOLEN FROM VTREEEXPLORER.VIM]]
|
||||
"Determine the number of windows open to this buffer number.
|
||||
@@ -1328,21 +1411,65 @@ function! s:BufInWindows(bnum)
|
||||
return cnt
|
||||
endfunction " >>>
|
||||
|
||||
"FUNCTION: s:InitNerdTree(dir) {{{2
|
||||
"Initialized the NERD tree, where the root will be initialized with the given
|
||||
"directory
|
||||
"FUNCTION: s:ClearAllBookmarks() {{{2
|
||||
"delete all bookmarks
|
||||
function! s:ClearAllBookmarks()
|
||||
for name in keys(g:NERDTreeBookmarks)
|
||||
let node = {}
|
||||
try
|
||||
let node = s:GetNodeForBookmark(name, 1)
|
||||
catch /NERDTree/
|
||||
endtry
|
||||
call remove(g:NERDTreeBookmarks, name)
|
||||
if !empty(node)
|
||||
call node.path.CacheBookmarkNames()
|
||||
endif
|
||||
endfor
|
||||
call s:WriteBookmarks()
|
||||
endfunction
|
||||
"FUNCTION: s:GetNodeForBookmark(name, searchFromAbsoluteRoot) {{{2
|
||||
"get the treenode for the bookmark with the given name
|
||||
"
|
||||
"Arg:
|
||||
"dir: the dir to init the root with
|
||||
function! s:InitNerdTree(dir)
|
||||
let dir = a:dir == '' ? expand('%:p:h') : a:dir
|
||||
"Args:
|
||||
"name: name of bookmark
|
||||
"searchFromAbsoluteRoot: specifies wheather we should search from the current
|
||||
"tree root, or the highest cached node
|
||||
function! s:GetNodeForBookmark(name, searchFromAbsoluteRoot)
|
||||
try
|
||||
let bookmark = s:GetBookmarks()[a:name]
|
||||
catch /E716/ "key not in dictionary error
|
||||
throw "NERDTree.BookmarkDoesntExist no bookmark found with name: " . a:name
|
||||
endtry
|
||||
|
||||
let searchRoot = a:searchFromAbsoluteRoot ? s:AbsoluteTreeRoot() : t:NERDTreeRoot
|
||||
let targetNode = searchRoot.FindNode(bookmark)
|
||||
if empty(targetNode)
|
||||
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . a:name
|
||||
endif
|
||||
return targetNode
|
||||
endfunction
|
||||
"FUNCTION: s:InitNerdTree(name) {{{2
|
||||
"Initialise the nerd tree for this tab. The tree will start in either the
|
||||
"given directory, or the directory associated with the given bookmark
|
||||
"
|
||||
"Args:
|
||||
"name: the name of a bookmark or a directory
|
||||
function! s:InitNerdTree(name)
|
||||
let path = {}
|
||||
if count(keys(s:GetBookmarks()), a:name)
|
||||
let path = s:GetBookmarks()[a:name]
|
||||
else
|
||||
let dir = a:name == '' ? expand('%:p:h') : a:name
|
||||
let dir = resolve(dir)
|
||||
|
||||
try
|
||||
let path = s:oPath.New(dir)
|
||||
|
||||
if !path.isDirectory
|
||||
call s:EchoWarning("Error reading: " . dir)
|
||||
catch /NERDTree.Path.InvalidArguments/
|
||||
call s:Echo("No bookmark or directory found for: " . a:name)
|
||||
return
|
||||
endtry
|
||||
endif
|
||||
if !path.isDirectory
|
||||
let path = path.GetParent()
|
||||
endif
|
||||
|
||||
"if instructed to, then change the vim CWD to the dir the NERDTree is
|
||||
@@ -1365,15 +1492,35 @@ function! s:InitNerdTree(dir)
|
||||
call t:NERDTreeRoot.Open()
|
||||
|
||||
call s:CreateTreeWin()
|
||||
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0)
|
||||
endfunction
|
||||
" Function: s:ReadBookmarks() {{{2
|
||||
function! s:ReadBookmarks()
|
||||
if filereadable(g:NERDTreeBookmarksFile)
|
||||
let bookmarks = s:GetBookmarks()
|
||||
let bookmarkStrings = readfile(g:NERDTreeBookmarksFile)
|
||||
for i in bookmarkStrings
|
||||
let key = substitute(i, '^\(\w.\{-}\) .*$', '\1', '')
|
||||
let path = substitute(i, '^\w.\{-} \(.*\)$', '\1', '')
|
||||
let bookmarks[key] = s:oPath.New(path)
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:TreeExistsForTab() {{{2
|
||||
" Returns 1 if a nerd tree root exists in the current tab
|
||||
function! s:TreeExistsForTab()
|
||||
return exists("t:NERDTreeRoot")
|
||||
endfunction
|
||||
" Function: s:WriteBookmarks() {{{2
|
||||
function! s:WriteBookmarks()
|
||||
let bookmarks = s:GetBookmarks()
|
||||
let bookmarkStrings = []
|
||||
for k in keys(bookmarks)
|
||||
call add(bookmarkStrings, k . ' ' . bookmarks[k].StrForOS(0))
|
||||
endfor
|
||||
call writefile(bookmarkStrings, g:NERDTreeBookmarksFile)
|
||||
endfunction
|
||||
|
||||
" SECTION: Public Functions {{{1
|
||||
"============================================================
|
||||
@@ -1596,7 +1743,7 @@ function! s:DumpHelp()
|
||||
let @h=@h."\" \n\" ----------------------------\n"
|
||||
let @h=@h."\" Directory node mappings~\n"
|
||||
let @h=@h."\" ". (g:NERDTreeMouseMode == 1 ? "double" : "single") ."-click,\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open/close node \n"
|
||||
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open & close node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapOpenRecursively .": recursively open node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseDir .": close parent of node\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapCloseChildren .": close all child nodes of\n"
|
||||
@@ -1637,6 +1784,14 @@ function! s:DumpHelp()
|
||||
let @h=@h."\" Other mappings~\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapQuit .": Close the NERDTree window\n"
|
||||
let @h=@h."\" ". g:NERDTreeMapHelp .": toggle help\n"
|
||||
let @h=@h."\" \n\" ----------------------------\n"
|
||||
let @h=@h."\" Bookmark commands~\n"
|
||||
let @h=@h."\" :Bookmark <name>\n"
|
||||
let @h=@h."\" :BookmarkToRoot <name>\n"
|
||||
let @h=@h."\" :RevealBookmark <name>\n"
|
||||
let @h=@h."\" :OpenBookmark <name>\n"
|
||||
let @h=@h."\" :ClearBookmarks [<names>]\n"
|
||||
let @h=@h."\" :ClearAllBookmarks\n"
|
||||
else
|
||||
let @h="\" Press ". g:NERDTreeMapHelp ." for help\n"
|
||||
endif
|
||||
@@ -1672,6 +1827,12 @@ function! s:EchoError(msg)
|
||||
call s:Echo(a:msg)
|
||||
echohl normal
|
||||
endfunction
|
||||
" FUNCTION: s:FindBookmarks(A,L,P) {{{2
|
||||
" completion function for the bookmark commands
|
||||
function! s:FindBookmarks(A,L,P)
|
||||
let keys = keys(s:GetBookmarks())
|
||||
return filter(keys, 'v:val =~ "^' . a:A . '"')
|
||||
endfunction
|
||||
"FUNCTION: s:FindNodeLineNumber(treenode){{{2
|
||||
"Finds the line number for the given tree node
|
||||
"
|
||||
@@ -1724,7 +1885,7 @@ function! s:FindNodeLineNumber(treenode)
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:FindRootNodeLineNumber(path){{{2
|
||||
"FUNCTION: s:FindRootNodeLineNumber(){{{2
|
||||
"Finds the line number of the root node
|
||||
function! s:FindRootNodeLineNumber()
|
||||
let rootLine = 1
|
||||
@@ -1734,6 +1895,14 @@ function! s:FindRootNodeLineNumber()
|
||||
return rootLine
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:GetBookmarks(name) {{{2
|
||||
" getter/lazy initializer for the g:NERDTreeBookmarks hash
|
||||
function! s:GetBookmarks()
|
||||
if !exists("g:NERDTreeBookmarks")
|
||||
let g:NERDTreeBookmarks = {}
|
||||
endif
|
||||
return g:NERDTreeBookmarks
|
||||
endfunction
|
||||
"FUNCTION: s:GetPath(ln) {{{2
|
||||
"Gets the full path to the node that is rendered on the given line number
|
||||
"
|
||||
@@ -1772,9 +1941,6 @@ function! s:GetPath(ln)
|
||||
let wasdir = 0
|
||||
if curFile =~ '/$'
|
||||
let wasdir = 1
|
||||
endif
|
||||
let curFile = substitute (curFile,' -> .*',"","") " remove link to
|
||||
if wasdir == 1
|
||||
let curFile = substitute(curFile, '/\?$', '/', "")
|
||||
endif
|
||||
|
||||
@@ -1784,24 +1950,19 @@ function! s:GetPath(ln)
|
||||
while lnum > 0
|
||||
let lnum = lnum - 1
|
||||
let curLine = getline(lnum)
|
||||
let curLineStripped = s:StripMarkupFromLine(curLine, 1)
|
||||
|
||||
"have we reached the top of the tree?
|
||||
if curLine =~ '^/'
|
||||
let sd = substitute (curLine, '[ ]*$', "", "")
|
||||
let dir = sd . dir
|
||||
let dir = substitute (curLine, ' *$', "", "") . dir
|
||||
break
|
||||
endif
|
||||
if curLine =~ '/$'
|
||||
if curLineStripped =~ '/$'
|
||||
let lpindent = match(curLine,s:tree_markup_reg_neg) / s:tree_wid
|
||||
if lpindent < indent
|
||||
let indent = indent - 1
|
||||
let sd = substitute (curLine, '^' . s:tree_markup_reg . '*',"","")
|
||||
let sd = substitute (sd, ' -> .*', '',"")
|
||||
|
||||
" remove leading escape
|
||||
let sd = substitute (sd,'^\\', "", "")
|
||||
|
||||
let dir = sd . dir
|
||||
let dir = substitute (curLineStripped,'^\\', "", "") . dir
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
@@ -1885,7 +2046,7 @@ function! s:JumpToChild(direction)
|
||||
endif
|
||||
endif
|
||||
|
||||
call s:PutCursorOnNode(targetNode, 1)
|
||||
call s:PutCursorOnNode(targetNode, 1, 0)
|
||||
|
||||
call s:CenterView()
|
||||
endfunction
|
||||
@@ -1903,6 +2064,18 @@ function! s:OpenDirNodeSplit(treenode)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:OpenExplorerFor(treenode) {{{2
|
||||
" opens a netrw window for the given dir treenode
|
||||
function! s:OpenExplorerFor(treenode)
|
||||
let oldwin = winnr()
|
||||
wincmd p
|
||||
if oldwin == winnr() || (&modified && s:BufInWindows(winbufnr(winnr())) < 2)
|
||||
wincmd p
|
||||
call s:OpenDirNodeSplit(a:treenode)
|
||||
else
|
||||
exec ("silent edit " . a:treenode.path.StrForEditCmd())
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: s:OpenFileNode(treenode) {{{2
|
||||
"Open the file represented by the given node in the current window, splitting
|
||||
"the window if needed
|
||||
@@ -1917,7 +2090,7 @@ function! s:OpenFileNode(treenode)
|
||||
else
|
||||
try
|
||||
wincmd p
|
||||
exec ("edit " . a:treenode.path.StrForEditCmd())
|
||||
silent exec ("edit " . a:treenode.path.StrForEditCmd())
|
||||
catch /^Vim\%((\a\+)\)\=:E37/
|
||||
call s:PutCursorInTreeWin()
|
||||
call s:Echo("Cannot open file, it is already open and modified")
|
||||
@@ -2041,19 +2214,31 @@ function! s:PromptToDelBuffer(bufnum, msg)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:PutCursorOnNode(treenode, is_jump){{{2
|
||||
"FUNCTION: s:PutCursorOnNode(treenode, isJump, recurseUpward){{{2
|
||||
"Places the cursor on the line number representing the given node
|
||||
"
|
||||
"Args:
|
||||
"treenode: the node to put the cursor on
|
||||
"is_jump: 1 if this cursor movement should be counted as a jump by vim
|
||||
function! s:PutCursorOnNode(treenode, is_jump)
|
||||
"isJump: 1 if this cursor movement should be counted as a jump by vim
|
||||
"recurseUpward: try to put the cursor on the parent if the this node isnt
|
||||
"visible
|
||||
function! s:PutCursorOnNode(treenode, isJump, recurseUpward)
|
||||
let ln = s:FindNodeLineNumber(a:treenode)
|
||||
if ln != -1
|
||||
if a:is_jump
|
||||
if a:isJump
|
||||
mark '
|
||||
endif
|
||||
call cursor(ln, col("."))
|
||||
else
|
||||
if a:recurseUpward
|
||||
let node = a:treenode
|
||||
while s:FindNodeLineNumber(node) == -1 && node != {}
|
||||
let node = node.parent
|
||||
call node.Open()
|
||||
endwhile
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(a:treenode, a:isJump, 0)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -2107,9 +2292,12 @@ function! s:RenderView()
|
||||
:silent 1,1delete _
|
||||
|
||||
"restore the view
|
||||
let old_scrolloff=&scrolloff
|
||||
let &scrolloff=0
|
||||
call cursor(topLine, 1)
|
||||
normal! zt
|
||||
call cursor(curLine, curCol)
|
||||
let &scrolloff = old_scrolloff
|
||||
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
@@ -2129,7 +2317,7 @@ function! s:RenderViewSavingPosition()
|
||||
call s:RenderView()
|
||||
|
||||
if currentNode != {}
|
||||
call s:PutCursorOnNode(currentNode, 0)
|
||||
call s:PutCursorOnNode(currentNode, 0, 0)
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: s:RestoreScreenState() {{{2
|
||||
@@ -2185,19 +2373,23 @@ function! s:SetupSyntaxHighlighting()
|
||||
syn match treeHelpTitle #" .*\~#hs=s+2,he=e-1 contains=treeFlag
|
||||
syn match treeToggleOn #".*(on)#hs=e-2,he=e-1 contains=treeHelpKey
|
||||
syn match treeToggleOff #".*(off)#hs=e-3,he=e-1 contains=treeHelpKey
|
||||
syn match treeHelp #^" .*# contains=treeHelpKey,treeHelpTitle,treeFlag,treeToggleOff,treeToggleOn
|
||||
syn match treeHelpCommand #" :.\{-}\>#hs=s+3
|
||||
syn match treeHelp #^" .*# contains=treeHelpKey,treeHelpTitle,treeFlag,treeToggleOff,treeToggleOn,treeHelpCommand
|
||||
|
||||
"highlighting for sym links
|
||||
syn match treeLink #[^-| `].* -> #
|
||||
syn match treeLink #[^-| `].* -> # contains=treeBookmark
|
||||
|
||||
"highlighting for readonly files
|
||||
syn match treeRO #[0-9a-zA-Z]\+.*\[RO\]# contains=treeFlag
|
||||
syn match treeRO #[0-9a-zA-Z]\+.*\[RO\]# contains=treeFlag,treeBookmark
|
||||
|
||||
"highlighting for bookmarks
|
||||
syn match treeBookmark # {.*}#hs=s+1
|
||||
|
||||
"highlighing for directory nodes and file nodes
|
||||
syn match treeDirSlash #/#
|
||||
syn match treeDir #[^-| `].*/\([ {}]\{4\}\)*$# contains=treeLink,treeDirSlash,treeOpenable,treeClosable
|
||||
syn match treeFile #|-.*# contains=treeLink,treePart,treeRO,treePartFile
|
||||
syn match treeFile #`-.*# contains=treeLink,treePart,treeRO,treePartFile
|
||||
syn match treeDir #[^-| `].*/# contains=treeLink,treeDirSlash,treeOpenable,treeClosable
|
||||
syn match treeFile #|-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark
|
||||
syn match treeFile #`-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark
|
||||
syn match treeCWD #^/.*$#
|
||||
|
||||
if g:NERDChristmasTree
|
||||
@@ -2215,6 +2407,7 @@ function! s:SetupSyntaxHighlighting()
|
||||
|
||||
hi def link treeHelp String
|
||||
hi def link treeHelpKey Identifier
|
||||
hi def link treeHelpCommand Identifier
|
||||
hi def link treeHelpTitle Macro
|
||||
hi def link treeToggleOn Question
|
||||
hi def link treeToggleOff WarningMsg
|
||||
@@ -2226,6 +2419,7 @@ function! s:SetupSyntaxHighlighting()
|
||||
hi def link treeOpenable Title
|
||||
hi def link treeFlag ignore
|
||||
hi def link treeRO WarningMsg
|
||||
hi def link treeBookmark Statement
|
||||
|
||||
hi def link NERDTreeCurrentNode Search
|
||||
endfunction
|
||||
@@ -2249,7 +2443,7 @@ function! s:ShouldSplitToOpen(winnumber)
|
||||
return winnr("$") == 1 || (modified && s:BufInWindows(winbufnr(a:winnumber)) < 2)
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:StripMarkupFromLine(line){{{2
|
||||
"FUNCTION: s:StripMarkupFromLine(line, removeLeadingSpaces){{{2
|
||||
"returns the given line with all the tree parts stripped off
|
||||
"
|
||||
"Args:
|
||||
@@ -2264,6 +2458,9 @@ function! s:StripMarkupFromLine(line, removeLeadingSpaces)
|
||||
"strip off any read only flag
|
||||
let line = substitute (line, s:tree_RO_str_reg, "","")
|
||||
|
||||
"strip off any bookmark flags
|
||||
let line = substitute (line, ' {[^}]*}', "","")
|
||||
|
||||
let wasdir = 0
|
||||
if line =~ '/$'
|
||||
let wasdir = 1
|
||||
@@ -2319,7 +2516,7 @@ function! s:ActivateNode()
|
||||
if treenode.path.isDirectory
|
||||
call treenode.ToggleOpen()
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(treenode, 0)
|
||||
call s:PutCursorOnNode(treenode, 0, 0)
|
||||
else
|
||||
call s:OpenFileNode(treenode)
|
||||
endif
|
||||
@@ -2375,8 +2572,56 @@ function! s:BindMappings()
|
||||
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTabSilent ." :call <SID>OpenNodeNewTab(1)<cr>"
|
||||
|
||||
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenExpl ." :call <SID>OpenExplorer()<cr>"
|
||||
|
||||
command! -buffer -nargs=1 Bookmark :call <SID>BookmarkNode('<args>')
|
||||
command! -buffer -complete=customlist,s:FindBookmarks -nargs=1 RevealBookmark :call <SID>RevealBookmark('<args>')
|
||||
command! -buffer -complete=customlist,s:FindBookmarks -nargs=1 OpenBookmark :call <SID>OpenBookmark('<args>')
|
||||
command! -buffer -complete=customlist,s:FindBookmarks -nargs=* ClearBookmarks call <SID>ClearBookmarks('<args>')
|
||||
command! -buffer -complete=customlist,s:FindBookmarks -nargs=+ BookmarkToRoot call <SID>BookmarkToRoot('<args>')
|
||||
command! -buffer -nargs=0 ClearAllBookmarks call <SID>ClearAllBookmarks() <bar> call <SID>RenderView()
|
||||
command! -buffer -nargs=0 ReadBookmarks call <SID>ReadBookmarks() <bar> call <SID>RenderView()
|
||||
command! -buffer -nargs=0 WriteBookmarks call <SID>WriteBookmarks()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:BookmarkNode(name) {{{2
|
||||
" Associate the current node with the given name
|
||||
function! s:BookmarkNode(name)
|
||||
if a:name !~ '^[0-9a-zA-Z_]*$'
|
||||
call s:Echo("Bookmarks must be named using numbers, letters and underscores only")
|
||||
return
|
||||
endif
|
||||
|
||||
let currentNode = s:GetSelectedNode()
|
||||
if currentNode != {}
|
||||
|
||||
try
|
||||
let oldMarkedNode = s:GetNodeForBookmark(a:name, 1)
|
||||
call oldMarkedNode.path.UncacheBookmark(a:name)
|
||||
catch /NERDTree.Bookmark\(DoesntExist\|NotFound\)/
|
||||
endtry
|
||||
|
||||
let bookmarks = s:GetBookmarks()
|
||||
let bookmarks[a:name] = currentNode.path
|
||||
call currentNode.path.CacheBookmarkNames()
|
||||
call s:WriteBookmarks()
|
||||
call s:RenderView()
|
||||
else
|
||||
call s:Echo("select a node first")
|
||||
endif
|
||||
endfunction
|
||||
" FUNCTION: s:BookmarkToRoot(name) {{{2
|
||||
" Make the node for the given bookmark the new tree root
|
||||
function! s:BookmarkToRoot(name)
|
||||
try
|
||||
let targetNode = s:GetNodeForBookmark(a:name, 1)
|
||||
catch /NERDTree.BookmarkNotFound/
|
||||
let bookmarks = s:GetBookmarks()
|
||||
let targetNode = s:oTreeFileNode.New(bookmarks[a:name])
|
||||
endtry
|
||||
call targetNode.MakeRoot()
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(targetNode, 0, 0)
|
||||
endfunction
|
||||
"FUNCTION: s:CheckForActivate() {{{2
|
||||
"Checks if the click should open the current node, if so then activate() is
|
||||
"called (directories are automatically opened if the symbol beside them is
|
||||
@@ -2425,27 +2670,42 @@ endfunction
|
||||
" changes the current root to the selected one
|
||||
function! s:ChRoot()
|
||||
let treenode = s:GetSelectedNode()
|
||||
if treenode == {} || treenode.path.isDirectory == 0
|
||||
call s:Echo("Select a directory node first")
|
||||
if treenode == {}
|
||||
call s:Echo("Select a node first")
|
||||
return
|
||||
endif
|
||||
|
||||
if treenode.isOpen == 0
|
||||
call treenode.Open()
|
||||
endif
|
||||
|
||||
let t:NERDTreeRoot = treenode
|
||||
|
||||
"change dir to the dir of the new root if instructed to
|
||||
if g:NERDTreeChDirMode == 2
|
||||
exec "cd " . treenode.path.StrForEditCmd()
|
||||
endif
|
||||
|
||||
|
||||
call treenode.MakeRoot()
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(t:NERDTreeRoot, 0)
|
||||
call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:ClearBookmarks(bookmarks) {{{2
|
||||
function! s:ClearBookmarks(bookmarks)
|
||||
let bookmarks = s:GetBookmarks()
|
||||
if a:bookmarks == ''
|
||||
let currentNode = s:GetSelectedNode()
|
||||
if currentNode != {}
|
||||
call currentNode.ClearBookmarks()
|
||||
endif
|
||||
else
|
||||
for name in split(a:bookmarks, ' ')
|
||||
if count(keys(bookmarks), name)
|
||||
let node = {}
|
||||
try
|
||||
let node = s:GetNodeForBookmark(name, 1)
|
||||
catch /NERDTree/
|
||||
endtry
|
||||
call remove(bookmarks, name)
|
||||
if !empty(node)
|
||||
call node.path.CacheBookmarkNames()
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
call s:WriteBookmarks()
|
||||
call s:RenderView()
|
||||
endfunction
|
||||
" FUNCTION: s:CloseChildren() {{{2
|
||||
" closes all childnodes of the current node
|
||||
function! s:CloseChildren()
|
||||
@@ -2457,7 +2717,7 @@ function! s:CloseChildren()
|
||||
|
||||
call currentNode.CloseChildren()
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(currentNode, 0)
|
||||
call s:PutCursorOnNode(currentNode, 0, 0)
|
||||
endfunction
|
||||
" FUNCTION: s:CloseCurrentDir() {{{2
|
||||
" closes the parent dir of the current node
|
||||
@@ -2474,7 +2734,7 @@ function! s:CloseCurrentDir()
|
||||
else
|
||||
call treenode.parent.Close()
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(treenode.parent, 0)
|
||||
call s:PutCursorOnNode(treenode.parent, 0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -2492,6 +2752,9 @@ function! s:CopyNode()
|
||||
\ "", currentNode.path.Str(0))
|
||||
|
||||
if newNodePath != ""
|
||||
"strip trailing slash
|
||||
let newNodePath = substitute(newNodePath, '\/$', '', '')
|
||||
|
||||
let confirmed = 1
|
||||
if currentNode.path.CopyingWillOverwrite(newNodePath)
|
||||
echo "\nWarning: copying may overwrite files! Continue? (yN)"
|
||||
@@ -2501,12 +2764,13 @@ function! s:CopyNode()
|
||||
|
||||
if confirmed
|
||||
try
|
||||
call currentNode.Copy(newNodePath)
|
||||
let newNode = currentNode.Copy(newNodePath)
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(newNode, 0, 0)
|
||||
catch /^NERDTree/
|
||||
call s:EchoWarning("Could not copy node")
|
||||
endtry
|
||||
endif
|
||||
call s:RenderView()
|
||||
else
|
||||
call s:Echo("Copy aborted.")
|
||||
endif
|
||||
@@ -2635,7 +2899,7 @@ function! s:InsertNewNode()
|
||||
if parentNode.isOpen || !empty(parentNode.children)
|
||||
call parentNode.AddChild(newTreeNode, 1)
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(newTreeNode, 1)
|
||||
call s:PutCursorOnNode(newTreeNode, 1, 0)
|
||||
endif
|
||||
catch /^NERDTree/
|
||||
call s:EchoWarning("Node Not Created.")
|
||||
@@ -2660,7 +2924,7 @@ function! s:JumpToParent()
|
||||
let currentNode = s:GetSelectedNode()
|
||||
if !empty(currentNode)
|
||||
if !empty(currentNode.parent)
|
||||
call s:PutCursorOnNode(currentNode.parent, 1)
|
||||
call s:PutCursorOnNode(currentNode.parent, 1, 0)
|
||||
call s:CenterView()
|
||||
else
|
||||
call s:Echo("cannot jump to parent")
|
||||
@@ -2673,7 +2937,7 @@ endfunction
|
||||
" FUNCTION: s:JumpToRoot() {{{2
|
||||
" moves the cursor to the root node
|
||||
function! s:JumpToRoot()
|
||||
call s:PutCursorOnNode(t:NERDTreeRoot, 1)
|
||||
call s:PutCursorOnNode(t:NERDTreeRoot, 1, 0)
|
||||
call s:CenterView()
|
||||
endfunction
|
||||
|
||||
@@ -2700,7 +2964,7 @@ function! s:JumpToSibling(forward)
|
||||
endif
|
||||
|
||||
if !empty(sibling)
|
||||
call s:PutCursorOnNode(sibling, 1)
|
||||
call s:PutCursorOnNode(sibling, 1, 0)
|
||||
call s:CenterView()
|
||||
endif
|
||||
else
|
||||
@@ -2708,6 +2972,24 @@ function! s:JumpToSibling(forward)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:OpenBookmark(name) {{{2
|
||||
" put the cursor on the given bookmark and, if its a file, open it
|
||||
function! s:OpenBookmark(name)
|
||||
try
|
||||
let targetNode = s:GetNodeForBookmark(a:name, 0)
|
||||
call s:PutCursorOnNode(targetNode, 0, 1)
|
||||
redraw!
|
||||
catch /NERDTree.BookmarkNotFound/
|
||||
call s:Echo("note - target node is not cached")
|
||||
let bookmarks = s:GetBookmarks()
|
||||
let targetNode = s:oTreeFileNode.New(bookmarks[a:name])
|
||||
endtry
|
||||
if targetNode.path.isDirectory
|
||||
call s:OpenExplorerFor(targetNode)
|
||||
else
|
||||
call s:OpenFileNode(targetNode)
|
||||
endif
|
||||
endfunction
|
||||
" FUNCTION: s:OpenEntrySplit() {{{2
|
||||
" Opens the currently selected file from the explorer in a
|
||||
" new window
|
||||
@@ -2724,14 +3006,7 @@ endfunction
|
||||
function! s:OpenExplorer()
|
||||
let treenode = s:GetSelectedDir()
|
||||
if treenode != {}
|
||||
let oldwin = winnr()
|
||||
wincmd p
|
||||
if oldwin == winnr() || (&modified && s:BufInWindows(winbufnr(winnr())) < 2)
|
||||
wincmd p
|
||||
call s:OpenDirNodeSplit(treenode)
|
||||
else
|
||||
exec ("silent edit " . treenode.path.StrForEditCmd())
|
||||
endif
|
||||
call s:OpenExplorerFor(treenode)
|
||||
else
|
||||
call s:Echo("select a node first")
|
||||
endif
|
||||
@@ -2789,6 +3064,16 @@ function! s:PreviewNode(openNewWin)
|
||||
call s:PutCursorInTreeWin()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:RevealBookmark(name) {{{2
|
||||
" put the cursor on the node associate with the given name
|
||||
function! s:RevealBookmark(name)
|
||||
try
|
||||
let targetNode = s:GetNodeForBookmark(a:name, 0)
|
||||
call s:PutCursorOnNode(targetNode, 0, 1)
|
||||
catch /NERDTree.BookmarkDoesntExist/
|
||||
call s:Echo("Bookmark isnt cached under the current root")
|
||||
endtry
|
||||
endfunction
|
||||
" FUNCTION: s:RefreshRoot() {{{2
|
||||
" Reloads the current root. All nodes below this will be lost and the root dir
|
||||
" will be reloaded.
|
||||
@@ -2847,7 +3132,7 @@ function! s:RenameCurrent()
|
||||
call s:PromptToDelBuffer(bufnum, prompt)
|
||||
endif
|
||||
|
||||
call s:PutCursorOnNode(curNode, 1)
|
||||
call s:PutCursorOnNode(curNode, 1, 0)
|
||||
|
||||
redraw
|
||||
catch /^NERDTree/
|
||||
@@ -2944,8 +3229,8 @@ function! s:UpDir(keepState)
|
||||
endif
|
||||
|
||||
call s:RenderView()
|
||||
call s:PutCursorOnNode(oldRoot, 0)
|
||||
call s:PutCursorOnNode(oldRoot, 0, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
||||
|
||||
Reference in New Issue
Block a user