Compare commits

...

48 Commits

Author SHA1 Message Date
Martin Grenfell
3cb3227d56 some corrections to changelog 2008-07-05 12:19:12 +12:00
Martin Grenfell
f183d60b13 switch version to 2.12.0 2008-07-05 12:17:21 +12:00
Martin Grenfell
8c8cd29142 update changelog and credits 2008-07-05 12:00:08 +12:00
Martin Grenfell
83e8c144ed update the doc RE bookmark names 2008-07-02 22:40:51 +12:00
Martin Grenfell
06c7c53127 fix for swap files and opening in a split
when opening a file in a new split (with the <tab> map) we were doing
the :split with a "silent" modifier. This meant that a swap existed and
input was required from the user, the script would just freeze up
2008-07-02 22:38:47 +12:00
Martin Grenfell
ec682b1f9b fix bookmark highlighting and make it "quieter"
highlighting was still broken for bookmarks that werent alphanumeric
w/underscores. Also, highlight the path parts of the bookmarks table as
"normal" so they dont demand as much attention
2008-07-02 22:24:31 +12:00
Martin Grenfell
7a15d9879f use s:Echo instead of :echo 2008-07-02 21:22:51 +12:00
Martin Grenfell
dea37444bc loosen bookmark name restrictions
now the only rule is that they cant contain spaces
2008-07-02 21:22:26 +12:00
Martin Grenfell
f5a20e5379 fix some bugs when dealing with invalid bookmarks 2008-07-02 21:15:28 +12:00
Martin Grenfell
a0573c51b1 update the doc and changelog 2008-07-01 22:54:40 +12:00
Martin Grenfell
d0cb14c7ce make every tab have its own filter settings
The tree filters for files/hidden-files/bookmarks now operate off tab
local variables which default to the global variables when a nerd tree
is initialised in the tab. Note: the file-filter already operated in
this way.

This means that each tree/tab has its own filter settings that are
initialised to the users preferences as specified by the global
variables, but can be altered independently of the other trees/tabs
2008-07-01 22:42:19 +12:00
Martin Grenfell
f2b2327c24 merge bookmark name caching with path string caching
We needed to change how the bookmark name caching was done to work with
the new path-display-string caching. It has now been merged into path
string caching.
2008-07-01 21:13:21 +12:00
Martin Grenfell
9d5a940be3 clear cached display string when path is refreshed
when the path object is refreshed, force the display string to be
recalculated
2008-07-01 14:23:38 +12:00
Martin Grenfell
38d91b66b0 cache display string 2008-07-01 14:23:13 +12:00
Martin Grenfell
65ebd30334 fix a bug when overwriting an existing bookmark
if the bookmark wasnt cached in the tree an exception was being thrown
that wasnt caught
2008-06-30 18:26:35 +12:00
Martin Grenfell
1998cef2b4 highlighting fix - allow numbers in bookmark names 2008-06-30 09:37:44 +12:00
Martin Grenfell
030cff2eda sort bookmarks when we add a new one 2008-06-30 09:36:50 +12:00
Martin Grenfell
02facac20a make bookmark width take into account the line numbers 2008-06-30 09:26:18 +12:00
Martin Grenfell
7789ccb90a update changelog 2008-06-29 21:20:40 +12:00
Martin Grenfell
d497c9ae9c small doc update for bookmarks 2008-06-29 20:08:27 +12:00
Martin Grenfell
cdf1e8d6e9 update the doc around the NERDTreeWinPos option 2008-06-29 19:55:56 +12:00
Martin Grenfell
5f4a002787 combine NERDTreeSplitVertical and NERDTreeWinPos
instead of using 2 options to specify the position of the tree, just use
NERDTreeWinPos and set it to "left", "right", "top", "bottom"
2008-06-29 19:43:50 +12:00
Martin Grenfell
c34968d282 add quickhelp doc for new t/T map functionality 2008-06-29 13:52:04 +12:00
Martin Grenfell
f76f983182 add doc for the changes to the t/T mappings 2008-06-29 13:49:29 +12:00
Martin Grenfell
312ce93bb4 make the t/T mappings work for bookmarks
when you hit t/T on a bookmark a new tab is opened and, if the bookmark
is a dir, a nerd tree is opened for that dir. If the bookmark is a file
then just open the file
2008-06-29 13:34:36 +12:00
Martin Grenfell
06776557cf add bookmark mappings to quickhelp 2008-06-29 12:42:52 +12:00
Martin Grenfell
d831cbf17b render bookmark paths as wide as the window allows 2008-06-29 12:35:05 +12:00
Martin Grenfell
aad2259522 add doc for bookmarks 2008-06-29 12:31:29 +12:00
Martin Grenfell
e1bd98fc7c open file bookmarks when user activates them
when the user activates a file bookmark open that file in the previous
window (i.e. do the 'o' mapping)
2008-06-29 01:00:55 +12:00
Martin Grenfell
7ca9b07b68 make NERDTreeShowBookmarks default to 0 2008-06-29 00:42:01 +12:00
Martin Grenfell
1532bf1922 move the bookmark->string code into the bookmark class 2008-06-29 00:41:34 +12:00
Martin Grenfell
ac544460e4 clean up/add comments to the bookmark methods 2008-06-29 00:33:25 +12:00
Martin Grenfell
d2989eb3e0 huge refactor, add bookmark class 2008-06-29 00:23:02 +12:00
Martin Grenfell
73be034d5e remove some random unneeded colons 2008-06-28 22:20:42 +12:00
Martin Grenfell
b5d6736f76 remove some old testing code 2008-06-28 22:20:09 +12:00
Martin Grenfell
1c38ffd30b add bookmark mapping to the quickhelp 2008-06-28 22:10:18 +12:00
Martin Grenfell
8e4b3565f8 turn bookmarks off by default 2008-06-28 21:43:00 +12:00
Martin Grenfell
31445645f7 truncate the bookmark path if its too long 2008-06-28 21:35:22 +12:00
Martin Grenfell
fc053917d8 add highlighting for bookmarks gui 2008-06-28 21:35:09 +12:00
Martin Grenfell
201df0a782 only show bookmark if NERDTreeShowBookmarks is set 2008-06-28 21:22:29 +12:00
Martin Grenfell
b59a7cd979 remove bookmarks display footer 2008-06-28 20:49:36 +12:00
Martin Grenfell
8f7aed712b add a mapping to toggle display of bookmarks 2008-06-28 20:44:55 +12:00
Martin Grenfell
3e946b1b4f make 'o' active bookmarks as well
hitting 'o' or clicking a bookmark will now make that bookmark to the
new tree root, in the same way that :BookmarkToRoot does
2008-06-28 20:43:33 +12:00
Martin Grenfell
2a16431b2d add bookmarks to the view 2008-06-28 20:42:00 +12:00
Martin Grenfell
6815622d2c add doc for NERDTreeQuitOnClose 2008-06-27 23:39:44 +12:00
Martin Grenfell
5c32c2a226 update help file to reflect the previous patch
* Add a doc section for the NERDTreeQuitOnOpen option.
  * Update changelog.
  * update credits.
2008-06-27 23:08:49 +12:00
Martin Grenfell
b363396a93 apply "NERDTreeQuitOnOpen" patch from Matan Nassau
with some slight modifications
2008-06-27 22:58:33 +12:00
Martin Grenfell
87382097df resize the tree window when it was the only one
if the nerd tree window is the only window open when the user opens a
file, the file will be opened in a new split. Previously that meant the
two windows would take up half the screen each.
2008-06-24 19:32:52 +12:00
2 changed files with 490 additions and 261 deletions

View File

@@ -22,7 +22,9 @@ CONTENTS *NERDTree-contents*
1.Intro...................................|NERDTree| 1.Intro...................................|NERDTree|
2.Functionality provided..................|NERDTreeFunctionality| 2.Functionality provided..................|NERDTreeFunctionality|
2.1 Global commands...................|NERDTreeGlobalCommands| 2.1 Global commands...................|NERDTreeGlobalCommands|
2.2 Bookmark commands.................|NERDTreeBookmarkCommands| 2.2 Bookmarks.........................|NERDTreeBookmarks|
2.2.1 The bookmark table..........|NERDTreeBookmarkTable|
2.2.2 Bookmark commands...........|NERDTreeBookmarkCommands|
2.3 NERD tree mappings................|NERDTreeMappings| 2.3 NERD tree mappings................|NERDTreeMappings|
2.4 The filesystem menu...............|NERDTreeFilesysMenu| 2.4 The filesystem menu...............|NERDTreeFilesysMenu|
3.Options.................................|NERDTreeOptions| 3.Options.................................|NERDTreeOptions|
@@ -110,18 +112,27 @@ The following features and functionality are provided by the NERD tree:
Close the NERD tree in this tab. Close the NERD tree in this tab.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2. Bookmark Commands *NERDTreeBookmarkCommands* 2.2. Bookmarks *NERDTreeBookmarks*
Bookmarks in the NERD tree are a way to tag files or directories of interest. 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. For example, you could use bookmarks to tag all of your project directories.
See also |:NERDTree| and |:NERDTreeFromBookmark|.
------------------------------------------------------------------------------
2.2.1. The Bookmark Table *NERDTreeBookmarkTable*
If the bookmark table is active (see |NERDTree-B| and
|NERDTreeShowBookmarks|), it will be rendered above the tree. You can double
click bookmarks or use the |NERDTree-o| mapping to activate them. See also,
|NERDTree-t| and |NERDTree-T|
------------------------------------------------------------------------------
2.2.2. Bookmark commands *NERDTreeBookmarkCommands*
Note that the following commands are only available in the NERD tree buffer. Note that the following commands are only available in the NERD tree buffer.
:Bookmark <name> :Bookmark <name>
Bookmark the current node as <name>. If there is already a <name> Bookmark the current node as <name>. If there is already a <name>
bookmark, it is overwritten. <name> must consist of alphanumeric bookmark, it is overwritten. <name> must not contain spaces.
characters and underscores.
:BookmarkToRoot <bookmark> :BookmarkToRoot <bookmark>
Make the directory corresponding to <bookmark> the new root. If a treenode Make the directory corresponding to <bookmark> the new root. If a treenode
@@ -147,15 +158,17 @@ Note that the following commands are only available in the NERD tree buffer.
:ClearAllBookmarks :ClearAllBookmarks
Remove all bookmarks. Remove all bookmarks.
See also |:NERDTree| and |:NERDTreeFromBookmark|.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.3. NERD tree Mappings *NERDTreeMappings* 2.3. NERD tree Mappings *NERDTreeMappings*
Default Description~ help-tag~ Default Description~ help-tag~
Key~ Key~
o.......Open selected file, or expand selected dir...............|NERDTree-o| o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go| go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node in a new tab..........................|NERDTree-t| t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T| T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
<tab>...Open selected file in a split window.....................|NERDTree-tab| <tab>...Open selected file in a split window.....................|NERDTree-tab|
g<tab>..Same as <tab>, but leave the cursor on the NERDTree......|NERDTree-gtab| g<tab>..Same as <tab>, but leave the cursor on the NERDTree......|NERDTree-gtab|
@@ -187,6 +200,7 @@ cd......Change the CWD to the dir of the selected node...........|NERDTree-cd|
H.......Toggle whether hidden files displayed....................|NERDTree-H| H.......Toggle whether hidden files displayed....................|NERDTree-H|
f.......Toggle whether the file filters are used.................|NERDTree-f| f.......Toggle whether the file filters are used.................|NERDTree-f|
F.......Toggle whether files are displayed.......................|NERDTree-F| F.......Toggle whether files are displayed.......................|NERDTree-F|
B.......Toggle whether the bookmark table is displayed...........|NERDTree-B|
q.......Close the NERDTree window................................|NERDTree-q| q.......Close the NERDTree window................................|NERDTree-q|
?.......Toggle the display of the quick help.....................|NERDTree-?| ?.......Toggle the display of the quick help.....................|NERDTree-?|
@@ -197,8 +211,16 @@ Default key: o
Map option: NERDTreeMapActivateNode Map option: NERDTreeMapActivateNode
Applies to: files and directories. Applies to: files and directories.
If a file node is selected, it is opened in the previous window. If a If a file node is selected, it is opened in the previous window.
directory is selected it is opened or closed depending on its current state.
If a directory is selected it is opened or closed depending on its current
state.
If a bookmark that links to a directory is selected then that directory
becomes the new root.
If a bookmark that links to a file is selected then that file is opened in the
previous window.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTree-go* *NERDTree-go*
@@ -221,6 +243,10 @@ Applies to: files and directories.
Opens the selected file in a new tab. If a directory is selected, a netrw is Opens the selected file in a new tab. If a directory is selected, a netrw is
opened in a new tab. opened in a new tab.
If a bookmark which points to a directory is selected, open a NERD tree for
that directory in a new tab. If the bookmark points to a file, open that file
in a new tab.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTree-T* *NERDTree-T*
Default key: T Default key: T
@@ -431,6 +457,14 @@ Applies to: no restrictions.
Toggles whether file nodes are displayed. Toggles whether file nodes are displayed.
------------------------------------------------------------------------------
*NERDTree-B*
Default key: B
Map option: NERDTreeMapToggleBookmarks
Applies to: no restrictions.
Toggles whether the bookmarks table is displayed.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTree-q* *NERDTree-q*
Default key: q Default key: q
@@ -523,6 +557,11 @@ NERD tree. These options should be set in your vimrc.
|NERDTreeMouseMode| Tells the NERD tree how to handle mouse |NERDTreeMouseMode| Tells the NERD tree how to handle mouse
clicks. clicks.
|NERDTreeQuitOnOpen| Closes the tree window after opening a file.
|NERDTreeShowBookmarks| Tells the NERD tree whether to display the
bookmarks table on startup.
|NERDTreeShowFiles| Tells the NERD tree whether to display files |NERDTreeShowFiles| Tells the NERD tree whether to display files
in the tree on startup. in the tree on startup.
@@ -535,14 +574,9 @@ NERD tree. These options should be set in your vimrc.
|NERDTreeSortOrder| Tell the NERD tree how to sort the nodes in |NERDTreeSortOrder| Tell the NERD tree how to sort the nodes in
the tree. the tree.
|NERDTreeSplitVertical| Tells the script whether the NERD tree should
be created by splitting the window vertically
or horizontally.
|NERDTreeWinPos| Tells the script where to put the NERD tree |NERDTreeWinPos| Tells the script where to put the NERD tree
window. window.
|NERDTreeWinSize| Sets the window size when the NERD tree is |NERDTreeWinSize| Sets the window size when the NERD tree is
opened. opened.
@@ -693,6 +727,24 @@ itself. For example, if you have the following node: >
then (to single click activate it) you must click somewhere in then (to single click activate it) you must click somewhere in
'application.rb'. 'application.rb'.
------------------------------------------------------------------------------
*NERDTreeQuitOnOpen*
Values: 0 or 1.
Default: 0
If set to 1, the NERD tree window will close after opening a file with the
|NERDTree-o| or |NERDTree-tab| mappings.
------------------------------------------------------------------------------
*NERDTreeShowBookmarks*
Values: 0 or 1.
Default: 0.
If this option is set to 1 then the bookmarks table will be displayed.
This option can be toggled dynamically, per tree, with the |NERDTree-B| mapping.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTreeShowFiles* *NERDTreeShowFiles*
Values: 0 or 1. Values: 0 or 1.
@@ -701,9 +753,9 @@ Default: 1.
If this option is set to 1 then files are displayed in the NERD tree. If it is If this option is set to 1 then files are displayed in the NERD tree. If it is
set to 0 then only directories are displayed. set to 0 then only directories are displayed.
This option can be toggled dynamically with the |NERDTree-F| mapping and is This option can be toggled dynamically, per tree, with the |NERDTree-F|
useful for drastically shrinking the tree when you are navigating to a mapping and is useful for drastically shrinking the tree when you are
different part of the tree. navigating to a different part of the tree.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTreeShowHidden* *NERDTreeShowHidden*
@@ -711,8 +763,8 @@ Values: 0 or 1.
Default: 0. Default: 0.
This option tells vim whether to display hidden files by default. This option This option tells vim whether to display hidden files by default. This option
can be dynamically toggled with the |NERDTree-H| mapping. can be dynamically toggled, per tree, with the |NERDTree-H| mapping. Use one
Use one of the follow lines to set this option: > of the follow lines to set this option: >
let NERDTreeShowHidden=0 let NERDTreeShowHidden=0
let NERDTreeShowHidden=1 let NERDTreeShowHidden=1
< <
@@ -761,30 +813,16 @@ Other examples: >
3. Dirs will appear first, then ruby and php. Swap files, bak files and vim 3. Dirs will appear first, then ruby and php. Swap files, bak files and vim
backup files will appear last with everything else preceding them. backup files will appear last with everything else preceding them.
------------------------------------------------------------------------------
*NERDTreeSplitVertical*
Values: 0 or 1.
Default: 1.
This option, along with |NERDTreeWinPos|, is used to determine where the NERD
tree window appears.
If it is set to 1 then the NERD tree window will appear on either the left or
right side of the screen (depending on the |NERDTreeWinPos| option).
If it set to 0 then the NERD tree window will appear at the top of the screen.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*NERDTreeWinPos* *NERDTreeWinPos*
Values: 0 or 1. Values: "left", "right", "top" or "bottom"
Default: 1. Default: "left".
This option works in conjunction with the |NERDTreeSplitVertical| option to This option is used to determine where NERD tree window is placed on the
determine where NERD tree window is placed on the screen. screen.
If the option is set to 1 then the NERD tree will appear on the left or top of "top" or "bottom", will cause a horizontal split to be created for the tree,
the screen (depending on the value of |NERDTreeSplitVertical|). If set to 0, while "left" and "right" will cause a vertical split.
the window will appear on the right or bottom of the screen.
This option is makes it possible to use two different explorer type This option is makes it possible to use two different explorer type
plugins simultaneously. For example, you could have the taglist plugin on the plugins simultaneously. For example, you could have the taglist plugin on the
@@ -836,6 +874,26 @@ fridge for later ;)
============================================================================== ==============================================================================
7. Changelog *NERDTreeChangelog* 7. Changelog *NERDTreeChangelog*
2.12.0
- added a UI for bookmarks. See :help NERDTreeBookmarkTable for details.
Thanks to Zhang Shuhan for testing and bug reports.
- relaxed the restrictions on bookmark names, now the only restriction is
that they cant contain spaces. This allows for e.g. Chinese bookmark
names. Thanks to Zhang Shuhan for the suggestion.
- combined the NERDTreeWinPos and NERDTreeSplitVertical options. See :help
NERDTreeWinPos.
- applied a patch from Matan Nassau to add the NERDTreeQuitOnOpen option
which closes the tree window after opening a file. See :help
NERDTreeQuitOnOpen.
- optimised the nerd tree rendering. Now it takes just over 1/3 of the time
it previously took to render.
- now the tree filter mappings toggle the filters "per tree" rather than
globally. The global filter variables are used to set the initial filter
settings for each new NERD tree.
- fix to window resizing when opening a file when NERD tree is the only
window open
- other fixes
2.11.0 2.11.0
- changes to the 'o' mapping when opening files: - changes to the 'o' mapping when opening files:
- dont clobber "special" windows (eg taglist/quickfix/etc). This should - dont clobber "special" windows (eg taglist/quickfix/etc). This should
@@ -1089,7 +1147,8 @@ Thanks to Olivier Yiptong for prompting me to make line numbers in the
NERD tree window optional. NERD tree window optional.
Thanks to Zhang Shuhan for all of his emails and testing to help improve the Thanks to Zhang Shuhan for all of his emails and testing to help improve the
NERD tree path handling. NERD tree path handling. Thanks also for suggesting the bookmarks gui, and for
testing and making suggestions and bugreports.
Thanks to Cory Echols for sending a patch to add the :NERDTreeClose command and Thanks to Cory Echols for sending a patch to add the :NERDTreeClose command and
set the NERD tree buffers filetype to 'nerdtree' set the NERD tree buffers filetype to 'nerdtree'
@@ -1100,6 +1159,7 @@ feature.
Thanks to Yuan Jiang for suggesting the "o" mapping shouldnt clobber "special" Thanks to Yuan Jiang for suggesting the "o" mapping shouldnt clobber "special"
windows, like taglist. windows, like taglist.
Thanks to Matan Nassau for the patch to add the NERDTreeQuitOnOpen option.
============================================================================== ==============================================================================
9. License *NERDTreeLicense* 9. License *NERDTreeLicense*

View File

@@ -2,7 +2,7 @@
" File: NERD_tree.vim " File: NERD_tree.vim
" Description: vim global plugin that provides a nice tree explorer " Description: vim global plugin that provides a nice tree explorer
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com> " Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
" Last Change: 23 June, 2008 " Last Change: 5 July, 2008
" License: This program is free software. It comes without any warranty, " License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute " 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 " it and/or modify it under the terms of the Do What The Fuck You
@@ -10,7 +10,7 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details. " See http://sam.zoy.org/wtfpl/COPYING for more details.
" "
" ============================================================================ " ============================================================================
let s:NERD_tree_version = '2.11.0' let s:NERD_tree_version = '2.12.0'
" SECTION: Script init stuff {{{1 " SECTION: Script init stuff {{{1
"============================================================ "============================================================
@@ -53,6 +53,8 @@ call s:InitVariable("g:NERDTreeHighlightCursorline", 1)
call s:InitVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks') call s:InitVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
call s:InitVariable("g:NERDTreeMouseMode", 1) call s:InitVariable("g:NERDTreeMouseMode", 1)
call s:InitVariable("g:NERDTreeNotificationThreshold", 100) call s:InitVariable("g:NERDTreeNotificationThreshold", 100)
call s:InitVariable("g:NERDTreeQuitOnOpen", 0)
call s:InitVariable("g:NERDTreeShowBookmarks", 0)
call s:InitVariable("g:NERDTreeShowFiles", 1) call s:InitVariable("g:NERDTreeShowFiles", 1)
call s:InitVariable("g:NERDTreeShowHidden", 0) call s:InitVariable("g:NERDTreeShowHidden", 0)
call s:InitVariable("g:NERDTreeShowLineNumbers", 0) call s:InitVariable("g:NERDTreeShowLineNumbers", 0)
@@ -71,8 +73,7 @@ endif
"once here "once here
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*') let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
call s:InitVariable("g:NERDTreeSplitVertical", 1) call s:InitVariable("g:NERDTreeWinPos", "left")
call s:InitVariable("g:NERDTreeWinPos", 1)
call s:InitVariable("g:NERDTreeWinSize", 31) call s:InitVariable("g:NERDTreeWinSize", 31)
let s:running_windows = has("win16") || has("win32") || has("win64") let s:running_windows = has("win16") || has("win32") || has("win64")
@@ -113,6 +114,7 @@ call s:InitVariable("g:NERDTreeMapPreviewSplit", "g" . NERDTreeMapOpenSplit)
call s:InitVariable("g:NERDTreeMapQuit", "q") call s:InitVariable("g:NERDTreeMapQuit", "q")
call s:InitVariable("g:NERDTreeMapRefresh", "r") call s:InitVariable("g:NERDTreeMapRefresh", "r")
call s:InitVariable("g:NERDTreeMapRefreshRoot", "R") call s:InitVariable("g:NERDTreeMapRefreshRoot", "R")
call s:InitVariable("g:NERDTreeMapToggleBookmarks", "B")
call s:InitVariable("g:NERDTreeMapToggleFiles", "F") call s:InitVariable("g:NERDTreeMapToggleFiles", "F")
call s:InitVariable("g:NERDTreeMapToggleFilters", "f") call s:InitVariable("g:NERDTreeMapToggleFilters", "f")
call s:InitVariable("g:NERDTreeMapToggleHidden", "H") call s:InitVariable("g:NERDTreeMapToggleHidden", "H")
@@ -140,22 +142,198 @@ endif
command! -n=? -complete=dir NERDTree :call s:InitNerdTree('<args>') command! -n=? -complete=dir NERDTree :call s:InitNerdTree('<args>')
command! -n=? -complete=dir NERDTreeToggle :call s:Toggle('<args>') command! -n=? -complete=dir NERDTreeToggle :call s:Toggle('<args>')
command! -n=0 NERDTreeClose :call s:CloseTreeIfOpen() command! -n=0 NERDTreeClose :call s:CloseTreeIfOpen()
command! -n=1 -complete=customlist,s:FindBookmarks NERDTreeFromBookmark call s:InitNerdTree('<args>') command! -n=1 -complete=customlist,s:CompleteBookmarks NERDTreeFromBookmark call s:InitNerdTree('<args>')
" SECTION: Auto commands {{{1 " SECTION: Auto commands {{{1
"============================================================ "============================================================
"Save the cursor position whenever we close the nerd tree "Save the cursor position whenever we close the nerd tree
exec "autocmd BufWinLeave *". s:NERDTreeWinName ."* :call <SID>SaveScreenState()" exec "autocmd BufWinLeave *". s:NERDTreeWinName ."* :call <SID>SaveScreenState()"
"cache bookmarks when vim loads "cache bookmarks when vim loads
autocmd VimEnter * call <SID>ReadBookmarks() autocmd VimEnter * call s:oBookmark.CacheBookmarks()
"SECTION: Classes {{{1 "SECTION: Classes {{{1
"============================================================ "============================================================
"CLASS: oBookmark {{{2
"============================================================
let s:oBookmark = {}
" FUNCTION: oBookmark.AddBookmark(name, path) {{{3
" Class method to add a new bookmark to the list, if a previous bookmark exists
" with the same name, just update the path for that bookmark
function! s:oBookmark.AddBookmark(name, path) dict
for i in s:oBookmark.Bookmarks()
if i.name == a:name
let i.path = a:path
return
endif
endfor
call add(s:oBookmark.Bookmarks(), s:oBookmark.New(a:name, a:path))
call s:oBookmark.Sort()
endfunction
" Function: oBookmark.Bookmarks() {{{3
" Class method to get all bookmarks. Lazily initializes the bookmarks global
" variable
function! s:oBookmark.Bookmarks() dict
if !exists("g:NERDTreeBookmarks")
let g:NERDTreeBookmarks = []
endif
return g:NERDTreeBookmarks
endfunction
" Function: oBookmark.BookmarkFor(name) {{{3
" Class method to get the bookmark that has the given name. {} is return if no
" bookmark is found
function! s:oBookmark.BookmarkFor(name) dict
for i in s:oBookmark.Bookmarks()
if i.name == a:name
return i
endif
endfor
return {}
endfunction
" Function: oBookmark.BookmarkNames() {{{3
" Class method to return an array of all bookmark names
function! s:oBookmark.BookmarkNames() dict
let names = []
for i in s:oBookmark.Bookmarks()
call add(names, i.name)
endfor
return names
endfunction
" FUNCTION: oBookmark.CacheBookmarks() {{{3
" Class method to read all bookmarks from the bookmarks file intialize
" bookmark objects for each one.
function! s:oBookmark.CacheBookmarks() dict
if filereadable(g:NERDTreeBookmarksFile)
let bookmarks = []
let bookmarkStrings = readfile(g:NERDTreeBookmarksFile)
let invalidBookmarksFound = 0
for i in bookmarkStrings
let name = substitute(i, '^\(.\{-}\) .*$', '\1', '')
let path = substitute(i, '^.\{-} \(.*\)$', '\1', '')
try
let bookmark = s:oBookmark.New(name, s:oPath.New(path))
call add(bookmarks, bookmark)
catch /NERDTree.Path.InvalidArguments/
let invalidBookmarksFound += 1
endtry
endfor
let g:NERDTreeBookmarks = bookmarks
if invalidBookmarksFound
call s:Echo(invalidBookmarksFound . " invalid bookmarks were read and discarded")
call s:oBookmark.Write()
endif
endif
endfunction
" FUNCTION: oBookmark.CompareTo(otherbookmark) {{{3
" Compare these two bookmarks for sorting purposes
function! s:oBookmark.CompareTo(otherbookmark) dict
return a:otherbookmark.name < self.name
endfunction
" FUNCTION: oBookmark.ClearAll() {{{3
" Class method to delete all bookmarks.
function! s:oBookmark.ClearAll() dict
for i in s:oBookmark.Bookmarks()
call i.Delete()
endfor
call s:oBookmark.Write()
endfunction
" FUNCTION: oBookmark.Delete() {{{3
" Delete this bookmark. If the node for this bookmark is under the current
" root, then recache bookmarks for its Path object
function! s:oBookmark.Delete() dict
let node = {}
try
let node = self.GetNode(1)
catch /NERDTree.BookmarkNotFound/
endtry
call remove(s:oBookmark.Bookmarks(), index(s:oBookmark.Bookmarks(), self))
if !empty(node)
call node.path.CacheDisplayString()
endif
endfunction
" FUNCTION: oBookmark.GetNode(searchFromAbsoluteRoot) {{{3
" Gets the treenode for this bookmark
"
" Args:
" searchFromAbsoluteRoot: specifies whether we should search from the current
" tree root, or the highest cached node
function! s:oBookmark.GetNode(searchFromAbsoluteRoot) dict
let searchRoot = a:searchFromAbsoluteRoot ? s:AbsoluteTreeRoot() : t:NERDTreeRoot
let targetNode = searchRoot.FindNode(self.path)
if empty(targetNode)
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . self.name
endif
return targetNode
endfunction
" FUNCTION: oBookmark.GetNodeForName(name, searchFromAbsoluteRoot) {{{3
" Class method that finds the bookmark with the given name and returns the
" treenode for it.
function! s:oBookmark.GetNodeForName(name, searchFromAbsoluteRoot) dict
let bookmark = s:oBookmark.BookmarkFor(a:name)
if bookmark == {}
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . a:name
endif
return bookmark.GetNode(a:searchFromAbsoluteRoot)
endfunction
" FUNCTION: oBookmark.New(name, path) {{{3
" Create a new bookmark object with the given name and path object
function! s:oBookmark.New(name, path) dict
if a:name =~ ' '
throw "NERDTree.IllegalBookmarkName illegal name:" . a:name
endif
let newBookmark = copy(self)
let newBookmark.name = a:name
let newBookmark.path = a:path
return newBookmark
endfunction
" Function: oBookmark.Sort() {{{3
" Class method that sorts all bookmarks
function! s:oBookmark.Sort() dict
let CompareFunc = function("s:CompareBookmarks")
call sort(s:oBookmark.Bookmarks(), CompareFunc)
endfunction
" Function: oBookmark.Str() {{{3
" Get the string that should be rendered in the view for this bookmark
function! s:oBookmark.Str() dict
let pathStrMaxLen = winwidth(s:GetTreeWinNum()) - 5 - len(self.name)
if &nu
let pathStrMaxLen = pathStrMaxLen - &numberwidth
endif
let pathStr = self.path.StrForOS(0)
if len(pathStr) > pathStrMaxLen
let pathStr = '<' . strpart(pathStr, len(pathStr) - pathStrMaxLen)
endif
return '>' . self.name . ' [' . pathStr . ']'
endfunction
" Function: oBookmark.Write() {{{3
" Class method to write all bookmarks to the bookmarks file
function! s:oBookmark.Write() dict
let bookmarkStrings = []
for i in s:oBookmark.Bookmarks()
call add(bookmarkStrings, i.name . ' ' . i.path.StrForOS(0))
endfor
call writefile(bookmarkStrings, g:NERDTreeBookmarksFile)
endfunction
"CLASS: oTreeFileNode {{{2 "CLASS: oTreeFileNode {{{2
"This class is the parent of the oTreeDirNode class and constitures the "This class is the parent of the oTreeDirNode class and constitures the
"'Component' part of the composite design pattern between the treenode "'Component' part of the composite design pattern between the treenode
"classes. "classes.
"============================================================ "============================================================
let s:oTreeFileNode = {} let s:oTreeFileNode = {}
"FUNCTION: oTreeFileNode.Bookmark(name) {{{3
"bookmark this node with a:name
function! s:oTreeFileNode.Bookmark(name) dict
try
let oldMarkedNode = s:oBookmark.GetNodeForName(a:name, 1)
call oldMarkedNode.path.CacheDisplayString()
catch /NERDTree.Bookmark\(DoesntExist\|NotFound\)/
endtry
call s:oBookmark.AddBookmark(a:name, self.path)
call self.path.CacheDisplayString()
call s:oBookmark.Write()
endfunction
"FUNCTION: oTreeFileNode.CacheParent {{{3 "FUNCTION: oTreeFileNode.CacheParent {{{3
"initializes self.parent if it isnt already "initializes self.parent if it isnt already
function! s:oTreeFileNode.CacheParent() dict function! s:oTreeFileNode.CacheParent() dict
@@ -181,13 +359,12 @@ endfunction
"FUNCTION: oTreeFileNode.ClearBookmarks() {{{3 "FUNCTION: oTreeFileNode.ClearBookmarks() {{{3
function! s:oTreeFileNode.ClearBookmarks() dict function! s:oTreeFileNode.ClearBookmarks() dict
let bookmarks = s:GetBookmarks() for i in s:oBookmark.Bookmarks()
for i in keys(bookmarks) if i.path.Equals(self.path)
if bookmarks[i].Equals(self.path) call i.Delete()
call remove(bookmarks, i)
end end
endfor endfor
call self.path.CacheBookmarkNames() call self.path.CacheDisplayString()
endfunction endfunction
"FUNCTION: oTreeFileNode.Copy(dest) {{{3 "FUNCTION: oTreeFileNode.Copy(dest) {{{3
function! s:oTreeFileNode.Copy(dest) dict function! s:oTreeFileNode.Copy(dest) dict
@@ -811,24 +988,38 @@ endfunction
"CLASS: oPath {{{2 "CLASS: oPath {{{2
"============================================================ "============================================================
let s:oPath = {} let s:oPath = {}
let oPath = s:oPath
"FUNCTION: oPath.BookmarkNames() {{{3 "FUNCTION: oPath.BookmarkNames() {{{3
function! s:oPath.BookmarkNames() dict function! s:oPath.BookmarkNames() dict
if !exists("self.bookmarkNames") if !exists("self.bookmark")
call self.CacheBookmarkNames() call self.CacheDisplayString()
endif endif
return self.bookmarkNames return self.bookmarkNames
endfunction endfunction
"FUNCTION: oPath.CacheBookmarkNames() {{{3 "FUNCTION: oPath.CacheDisplayString() {{{3
function! s:oPath.CacheBookmarkNames() dict function! s:oPath.CacheDisplayString() dict
let self.bookmarkNames = [] let self.cachedDisplayString = self.GetLastPathComponent(1)
let bookmarks = s:GetBookmarks()
for k in keys(bookmarks) if self.isExecutable
if bookmarks[k].Equals(self) let self.cachedDisplayString = self.cachedDisplayString . '*'
call add(self.bookmarkNames, k) endif
let bookmarkNames = []
for i in s:oBookmark.Bookmarks()
if i.path.Equals(self)
call add(bookmarkNames, i.name)
endif endif
endfor endfor
return self.bookmarkNames if !empty(bookmarkNames)
let self.cachedDisplayString .= ' {' . join(bookmarkNames) . '}'
endif
if self.isSymLink
let self.cachedDisplayString .= ' -> ' . self.symLinkDest
endif
if self.isReadOnly
let self.cachedDisplayString .= ' [RO]'
endif
endfunction endfunction
"FUNCTION: oPath.ChangeToDir() {{{3 "FUNCTION: oPath.ChangeToDir() {{{3
function! s:oPath.ChangeToDir() dict function! s:oPath.ChangeToDir() dict
@@ -1095,11 +1286,11 @@ function! s:oPath.Ignore() dict
endif endif
"dont show hidden files unless instructed to "dont show hidden files unless instructed to
if g:NERDTreeShowHidden == 0 && lastPathComponent =~ '^\.' if t:NERDTreeShowHidden == 0 && lastPathComponent =~ '^\.'
return 1 return 1
endif endif
if g:NERDTreeShowFiles == 0 && self.isDirectory == 0 if t:NERDTreeShowFiles == 0 && self.isDirectory == 0
return 1 return 1
endif endif
@@ -1135,6 +1326,8 @@ function! s:oPath.New(fullpath) dict
call newPath.ReadInfoFromDisk(a:fullpath) call newPath.ReadInfoFromDisk(a:fullpath)
let newPath.cachedDisplayString = ""
return newPath return newPath
endfunction endfunction
@@ -1191,7 +1384,7 @@ endfunction
"FUNCTION: oPath.Refresh() {{{3 "FUNCTION: oPath.Refresh() {{{3
function! s:oPath.Refresh() dict function! s:oPath.Refresh() dict
call self.ReadInfoFromDisk(self.StrForOS(0)) call self.ReadInfoFromDisk(self.StrForOS(0))
call self.CacheBookmarkNames() call self.CacheDisplayString()
endfunction endfunction
"FUNCTION: oPath.Rename() {{{3 "FUNCTION: oPath.Rename() {{{3
@@ -1258,26 +1451,11 @@ endfunction
"Return: "Return:
"a string that can be used in the view to represent this path "a string that can be used in the view to represent this path
function! s:oPath.StrDisplay() dict function! s:oPath.StrDisplay() dict
let toReturn = self.GetLastPathComponent(1) if self.cachedDisplayString == ""
call self.CacheDisplayString()
if self.isExecutable
let toReturn = toReturn . '*'
endif endif
let bookmarks = self.BookmarkNames() return self.cachedDisplayString
if !empty(bookmarks)
let toReturn .= ' {' . join(bookmarks, ',') . '}'
endif
if self.isSymLink
let toReturn .= ' -> ' . self.symLinkDest
endif
if self.isReadOnly
let toReturn .= ' [RO]'
endif
return toReturn
endfunction endfunction
"FUNCTION: oPath.StrForEditCmd() {{{3 "FUNCTION: oPath.StrForEditCmd() {{{3
@@ -1343,15 +1521,6 @@ function! s:oPath.StrTrunk() dict
return self.drive . '/' . join(self.pathSegments[0:-2], '/') return self.drive . '/' . join(self.pathSegments[0:-2], '/')
endfunction 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
call remove(bookmarks, i)
endif
endfunction
"FUNCTION: oPath.WinToUnixPath(pathstr){{{3 "FUNCTION: oPath.WinToUnixPath(pathstr){{{3
"Takes in a windows path and returns the unix equiv "Takes in a windows path and returns the unix equiv
" "
@@ -1419,42 +1588,16 @@ function! s:BufInWindows(bnum)
return cnt return cnt
endfunction " >>> endfunction " >>>
"FUNCTION: s:ClearAllBookmarks() {{{2 "FUNCTION: CompareBookmarks(first, second) {{{2
"delete all bookmarks "Compares two bookmarks
function! s:ClearAllBookmarks() function! s:CompareBookmarks(first, second)
for name in keys(g:NERDTreeBookmarks) return a:first.CompareTo(a:second)
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 endfunction
"FUNCTION: s:GetNodeForBookmark(name, searchFromAbsoluteRoot) {{{2
"get the treenode for the bookmark with the given name
"
"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 " FUNCTION: s:CompleteBookmarks(A,L,P) {{{2
let targetNode = searchRoot.FindNode(bookmark) " completion function for the bookmark commands
if empty(targetNode) function! s:CompleteBookmarks(A,L,P)
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . a:name return filter(s:oBookmark.BookmarkNames(), 'v:val =~ "^' . a:A . '"')
endif
return targetNode
endfunction endfunction
"FUNCTION: s:InitNerdTree(name) {{{2 "FUNCTION: s:InitNerdTree(name) {{{2
"Initialise the nerd tree for this tab. The tree will start in either the "Initialise the nerd tree for this tab. The tree will start in either the
@@ -1464,8 +1607,8 @@ endfunction
"name: the name of a bookmark or a directory "name: the name of a bookmark or a directory
function! s:InitNerdTree(name) function! s:InitNerdTree(name)
let path = {} let path = {}
if count(keys(s:GetBookmarks()), a:name) if s:oBookmark.BookmarkFor(a:name) != {}
let path = s:GetBookmarks()[a:name] let path = s:oBookmark.BookmarkFor(a:name).path
else else
let dir = a:name == '' ? expand('%:p:h') : a:name let dir = a:name == '' ? expand('%:p:h') : a:name
let dir = resolve(dir) let dir = resolve(dir)
@@ -1488,6 +1631,9 @@ function! s:InitNerdTree(name)
let t:treeShowHelp = 0 let t:treeShowHelp = 0
let t:NERDTreeIgnoreEnabled = 1 let t:NERDTreeIgnoreEnabled = 1
let t:NERDTreeShowFiles = g:NERDTreeShowFiles
let t:NERDTreeShowHidden = g:NERDTreeShowHidden
let t:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks
if s:TreeExistsForTab() if s:TreeExistsForTab()
if s:IsTreeOpen() if s:IsTreeOpen()
@@ -1503,43 +1649,11 @@ function! s:InitNerdTree(name)
call s:RenderView() call s:RenderView()
call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0) call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0)
endfunction endfunction
" Function: s:ReadBookmarks() {{{2
function! s:ReadBookmarks()
if filereadable(g:NERDTreeBookmarksFile)
let bookmarks = s:GetBookmarks()
let bookmarkStrings = readfile(g:NERDTreeBookmarksFile)
let invalidBookmarksFound = 0
for i in bookmarkStrings
let key = substitute(i, '^\(\w\{-}\) .*$', '\1', '')
let path = substitute(i, '^\w\{-} \(.*\)$', '\1', '')
try
let bookmarks[key] = s:oPath.New(path)
catch /NERDTree.Path.InvalidArguments/
let invalidBookmarksFound += 1
endtry
endfor
if invalidBookmarksFound
call s:Echo(invalidBookmarksFound . " invalid bookmarks were read and discarded")
call s:WriteBookmarks()
endif
endif
endfunction
" Function: s:TreeExistsForTab() {{{2 " Function: s:TreeExistsForTab() {{{2
" Returns 1 if a nerd tree root exists in the current tab " Returns 1 if a nerd tree root exists in the current tab
function! s:TreeExistsForTab() function! s:TreeExistsForTab()
return exists("t:NERDTreeRoot") return exists("t:NERDTreeRoot")
endfunction 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 " SECTION: Public Functions {{{1
"============================================================ "============================================================
"Returns the node that the cursor is currently on. "Returns the node that the cursor is currently on.
@@ -1624,8 +1738,8 @@ endfunction
"options etc "options etc
function! s:CreateTreeWin() function! s:CreateTreeWin()
"create the nerd tree window "create the nerd tree window
let splitLocation = g:NERDTreeWinPos ? "topleft " : "botright " let splitLocation = (g:NERDTreeWinPos == "top" || g:NERDTreeWinPos == "left") ? "topleft " : "botright "
let splitMode = g:NERDTreeSplitVertical ? "vertical " : "" let splitMode = s:ShouldSplitVertically() ? "vertical " : ""
let splitSize = g:NERDTreeWinSize let splitSize = g:NERDTreeWinSize
let t:NERDTreeWinName = localtime() . s:NERDTreeWinName let t:NERDTreeWinName = localtime() . s:NERDTreeWinName
let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeWinName let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeWinName
@@ -1770,6 +1884,13 @@ function! s:DumpHelp()
let @h=@h."\" ". g:NERDTreeMapOpenExpl.": Open netrw for selected\n" let @h=@h."\" ". g:NERDTreeMapOpenExpl.": Open netrw for selected\n"
let @h=@h."\" node\n" let @h=@h."\" node\n"
let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Bookmark table mappings~\n"
let @h=@h."\" double-click,\n"
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open bookmark\n"
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"
let @h=@h."\" ". g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
let @h=@h."\"\n\" ----------------------------\n" let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Tree navigation mappings~\n" let @h=@h."\" Tree navigation mappings~\n"
let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n" let @h=@h."\" ". g:NERDTreeMapJumpRoot .": go to root\n"
@@ -1794,9 +1915,10 @@ function! s:DumpHelp()
let @h=@h."\"\n\" ----------------------------\n" let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Tree filtering mappings~\n" let @h=@h."\" Tree filtering mappings~\n"
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (g:NERDTreeShowHidden ? "on" : "off") . ")\n" let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (t:NERDTreeShowHidden ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (t:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n" let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (t:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (g:NERDTreeShowFiles ? "on" : "off") . ")\n" let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (t:NERDTreeShowFiles ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (t:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
let @h=@h."\"\n\" ----------------------------\n" let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Other mappings~\n" let @h=@h."\" Other mappings~\n"
@@ -1845,12 +1967,6 @@ function! s:EchoError(msg)
call s:Echo(a:msg) call s:Echo(a:msg)
echohl normal echohl normal
endfunction 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 "FUNCTION: s:FindNodeLineNumber(treenode){{{2
"Finds the line number for the given tree node "Finds the line number for the given tree node
" "
@@ -1913,14 +2029,6 @@ function! s:FindRootNodeLineNumber()
return rootLine return rootLine
endfunction 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 "FUNCTION: s:GetPath(ln) {{{2
"Gets the full path to the node that is rendered on the given line number "Gets the full path to the node that is rendered on the given line number
" "
@@ -1989,6 +2097,17 @@ function! s:GetPath(ln)
return toReturn return toReturn
endfunction endfunction
"FUNCTION: s:GetSelectedBookmark() {{{2
"Returns the current node if it is a dir node, or else returns the current
"nodes parent
function! s:GetSelectedBookmark()
let line = getline(".")
let name = substitute(line, '^>\(.\{-}\) \[.*\]$', '\1', '')
if name != line
return s:oBookmark.BookmarkFor(name)
endif
endfunction
"FUNCTION: s:GetSelectedDir() {{{2 "FUNCTION: s:GetSelectedDir() {{{2
"Returns the current node if it is a dir node, or else returns the current "Returns the current node if it is a dir node, or else returns the current
"nodes parent "nodes parent
@@ -2164,16 +2283,16 @@ function! s:OpenNodeSplit(treenode)
" 'right' and 'below' will be set to the settings needed for " 'right' and 'below' will be set to the settings needed for
" splitbelow and splitright IF the explorer is the only window. " splitbelow and splitright IF the explorer is the only window.
" "
if g:NERDTreeSplitVertical == 1 if s:ShouldSplitVertically()
let there= g:NERDTreeWinPos ? "wincmd h" : "wincmd l" let there= g:NERDTreeWinPos == "left" ? "wincmd h" : "wincmd l"
let back= g:NERDTreeWinPos ? "wincmd l" : "wincmd h" let back = g:NERDTreeWinPos == "left" ? "wincmd l" : "wincmd h"
let right=g:NERDTreeWinPos ? 1 : 0 let right= g:NERDTreeWinPos == "left"
let below=0 let below=0
else else
let there= g:NERDTreeWinPos ? "wincmd k" : "wincmd j" let there= g:NERDTreeWinPos == "top" ? "wincmd k" : "wincmd j"
let back= g:NERDTreeWinPos ? "wincmd j" : "wincmd k" let back = g:NERDTreeWinPos == "top" ? "wincmd j" : "wincmd k"
let below= g:NERDTreeWinPos == "top"
let right=0 let right=0
let below=g:NERDTreeWinPos ? 1 : 0
endif endif
" Attempt to go to adjacent window " Attempt to go to adjacent window
@@ -2193,13 +2312,15 @@ function! s:OpenNodeSplit(treenode)
" Create a variable to use if splitting vertically " Create a variable to use if splitting vertically
let splitMode = "" let splitMode = ""
if (onlyOneWin && g:NERDTreeSplitVertical) || (!onlyOneWin && !g:NERDTreeSplitVertical) if (onlyOneWin && s:ShouldSplitVertically()) || (!onlyOneWin && !s:ShouldSplitVertically())
let splitMode = "vertical" let splitMode = "vertical"
endif endif
echomsg splitMode
" Open the new window " Open the new window
try try
exec("silent " . splitMode." sp " . a:treenode.path.StrForEditCmd()) exec(splitMode." sp " . a:treenode.path.StrForEditCmd())
catch /^Vim\%((\a\+)\)\=:E37/ catch /^Vim\%((\a\+)\)\=:E37/
call s:PutCursorInTreeWin() call s:PutCursorInTreeWin()
throw "NERDTree.view.FileOpen exception: ". a:treenode.path.Str(0) ." is already open and modified." throw "NERDTree.view.FileOpen exception: ". a:treenode.path.Str(0) ." is already open and modified."
@@ -2207,6 +2328,14 @@ function! s:OpenNodeSplit(treenode)
"do nothing "do nothing
endtry endtry
"resize the tree window if no other window was open before
if onlyOneWin
let size = exists("t:NERDTreeOldWindowSize") ? t:NERDTreeOldWindowSize : g:NERDTreeWinSize
exec(there)
exec("silent ". splitMode ." resize ". size)
wincmd p
endif
" Restore splitmode settings " Restore splitmode settings
let &splitbelow=savesplitbelow let &splitbelow=savesplitbelow
let &splitright=savesplitright let &splitright=savesplitright
@@ -2265,6 +2394,20 @@ function! s:PutCursorInTreeWin()
exec s:GetTreeWinNum() . "wincmd w" exec s:GetTreeWinNum() . "wincmd w"
endfunction endfunction
"FUNCTION: s:RenderBookmarks {{{2
function! s:RenderBookmarks()
call setline(line(".")+1, ">----------Bookmarks----------")
call cursor(line(".")+1, col("."))
for i in s:oBookmark.Bookmarks()
call setline(line(".")+1, i.Str())
call cursor(line(".")+1, col("."))
endfor
call setline(line(".")+1, '')
call cursor(line(".")+1, col("."))
endfunction
"FUNCTION: s:RenderView {{{2 "FUNCTION: s:RenderView {{{2
"The entry function for rendering the tree. Renders the root then calls "The entry function for rendering the tree. Renders the root then calls
"s:DrawTree to draw the children of the root "s:DrawTree to draw the children of the root
@@ -2282,7 +2425,7 @@ function! s:RenderView()
let topLine = line("w0") let topLine = line("w0")
"delete all lines in the buffer (being careful not to clobber a register) "delete all lines in the buffer (being careful not to clobber a register)
:silent 1,$delete _ silent 1,$delete _
call s:DumpHelp() call s:DumpHelp()
@@ -2290,6 +2433,10 @@ function! s:RenderView()
call setline(line(".")+1, "") call setline(line(".")+1, "")
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
if t:NERDTreeShowBookmarks
call s:RenderBookmarks()
endif
"add the 'up a dir' line "add the 'up a dir' line
call setline(line(".")+1, s:tree_up_dir_line) call setline(line(".")+1, s:tree_up_dir_line)
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
@@ -2302,7 +2449,7 @@ function! s:RenderView()
call s:DrawTree(t:NERDTreeRoot, 0, 0, [], t:NERDTreeRoot.GetChildCount() == 1) call s:DrawTree(t:NERDTreeRoot, 0, 0, [], t:NERDTreeRoot.GetChildCount() == 1)
"delete the blank line at the top of the buffer "delete the blank line at the top of the buffer
:silent 1,1delete _ silent 1,1delete _
"restore the view "restore the view
let old_scrolloff=&scrolloff let old_scrolloff=&scrolloff
@@ -2343,7 +2490,7 @@ function! s:RestoreScreenState()
if !exists("t:NERDTreeOldTopLine") || !exists("t:NERDTreeOldPos") || !exists("t:NERDTreeOldWindowSize") if !exists("t:NERDTreeOldTopLine") || !exists("t:NERDTreeOldPos") || !exists("t:NERDTreeOldWindowSize")
return return
endif endif
exec("silent ". (g:NERDTreeSplitVertical ? "vertical" : "") ." resize ".t:NERDTreeOldWindowSize) exec("silent ". (s:ShouldSplitVertically() ? "vertical" : "") ." resize ".t:NERDTreeOldWindowSize)
let old_scrolloff=&scrolloff let old_scrolloff=&scrolloff
let &scrolloff=0 let &scrolloff=0
@@ -2361,7 +2508,7 @@ endfunction
function! s:SaveScreenState() function! s:SaveScreenState()
let t:NERDTreeOldPos = getpos(".") let t:NERDTreeOldPos = getpos(".")
let t:NERDTreeOldTopLine = line("w0") let t:NERDTreeOldTopLine = line("w0")
let t:NERDTreeOldWindowSize = g:NERDTreeSplitVertical ? winwidth("") : winheight("") let t:NERDTreeOldWindowSize = s:ShouldSplitVertically() ? winwidth("") : winheight("")
endfunction endfunction
"FUNCTION: s:SetupSyntaxHighlighting() {{{2 "FUNCTION: s:SetupSyntaxHighlighting() {{{2
@@ -2394,13 +2541,9 @@ function! s:SetupSyntaxHighlighting()
syn match treeHelpCommand #" :.\{-}\>#hs=s+3 syn match treeHelpCommand #" :.\{-}\>#hs=s+3
syn match treeHelp #^".*# contains=treeHelpKey,treeHelpTitle,treeFlag,treeToggleOff,treeToggleOn,treeHelpCommand syn match treeHelp #^".*# contains=treeHelpKey,treeHelpTitle,treeFlag,treeToggleOff,treeToggleOn,treeHelpCommand
"highlighting for readonly files "highlighting for readonly files
syn match treeRO #[\/0-9a-zA-Z]\+.*\[RO\]# contains=treeFlag,treeBookmark syn match treeRO #[\/0-9a-zA-Z]\+.*\[RO\]# contains=treeFlag,treeBookmark
"highlighting for bookmarks
syn match treeBookmark # {.*}#hs=s+1
"highlighting for sym links "highlighting for sym links
syn match treeLink #[^-| `].* -> # contains=treeBookmark,treeOpenable,treeClosable,treeDirSlash syn match treeLink #[^-| `].* -> # contains=treeBookmark,treeOpenable,treeClosable,treeDirSlash
@@ -2412,6 +2555,15 @@ function! s:SetupSyntaxHighlighting()
syn match treeFile #`-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark,treeExecFile syn match treeFile #`-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark,treeExecFile
syn match treeCWD #^/.*$# syn match treeCWD #^/.*$#
"highlighting for bookmarks
syn match treeBookmark # {.*}#hs=s+1
"highlighting for the bookmarks table
syn match treeBookmarksLeader #^>#
syn match treeBookmarksHeader #^>-\+Bookmarks-\+$# contains=treeBookmarksLeader
syn match treeBookmarkName #^>.\{-} #he=e-1 contains=treeBookmarksLeader
syn match treeBookmark #^>.*$# contains=treeBookmarksLeader,treeBookmarkName,treeBookmarksHeader
if g:NERDChristmasTree if g:NERDChristmasTree
hi def link treePart Special hi def link treePart Special
hi def link treePartFile Type hi def link treePartFile Type
@@ -2426,6 +2578,11 @@ function! s:SetupSyntaxHighlighting()
hi def link treeClosable Title hi def link treeClosable Title
endif endif
hi def link treeBookmarksHeader statement
hi def link treeBookmarksLeader ignore
hi def link treeBookmarkName Identifier
hi def link treeBookmark normal
hi def link treeHelp String hi def link treeHelp String
hi def link treeHelpKey Identifier hi def link treeHelpKey Identifier
hi def link treeHelpCommand Identifier hi def link treeHelpCommand Identifier
@@ -2476,6 +2633,11 @@ function! s:ShouldSplitToOpen(winnumber)
return modified && s:BufInWindows(winbufnr(a:winnumber)) < 2 return modified && s:BufInWindows(winbufnr(a:winnumber)) < 2
endfunction endfunction
" Function: s:ShouldSplitVertically() {{{2
" Returns 1 if g:NERDTreeWinPos is 'left' or 'right'
function! s:ShouldSplitVertically()
return g:NERDTreeWinPos == 'left' || g:NERDTreeWinPos == 'right'
endfunction
"FUNCTION: s:StripMarkupFromLine(line, removeLeadingSpaces){{{2 "FUNCTION: s:StripMarkupFromLine(line, removeLeadingSpaces){{{2
"returns the given line with all the tree parts stripped off "returns the given line with all the tree parts stripped off
" "
@@ -2543,18 +2705,28 @@ function! s:ActivateNode()
if getline(".") == s:tree_up_dir_line if getline(".") == s:tree_up_dir_line
return s:UpDir(0) return s:UpDir(0)
endif endif
let treenode = s:GetSelectedNode()
if treenode == {}
call s:EchoWarning("cannot open selected entry")
return
endif
if treenode.path.isDirectory let treenode = s:GetSelectedNode()
call treenode.ToggleOpen() if treenode != {}
call s:RenderView() if treenode.path.isDirectory
call s:PutCursorOnNode(treenode, 0, 0) call treenode.ToggleOpen()
call s:RenderView()
call s:PutCursorOnNode(treenode, 0, 0)
else
call s:OpenFileNode(treenode)
if g:NERDTreeQuitOnOpen
call s:CloseTree()
endif
endif
else else
call s:OpenFileNode(treenode) let bookmark = s:GetSelectedBookmark()
if !empty(bookmark)
if bookmark.path.isDirectory
call s:BookmarkToRoot(bookmark.name)
else
call s:OpenFileNode(s:oTreeFileNode.New(bookmark.path))
endif
endif
endif endif
endfunction endfunction
@@ -2591,6 +2763,7 @@ function! s:BindMappings()
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleHidden ." :call <SID>ToggleShowHidden()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleHidden ." :call <SID>ToggleShowHidden()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleFilters ." :call <SID>ToggleIgnoreFilter()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleFilters ." :call <SID>ToggleIgnoreFilter()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleFiles ." :call <SID>ToggleShowFiles()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleFiles ." :call <SID>ToggleShowFiles()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapToggleBookmarks ." :call <SID>ToggleShowBookmarks()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapCloseDir ." :call <SID>CloseCurrentDir()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapCloseDir ." :call <SID>CloseCurrentDir()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapCloseChildren ." :call <SID>CloseChildren()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapCloseChildren ." :call <SID>CloseChildren()<cr>"
@@ -2604,43 +2777,32 @@ function! s:BindMappings()
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapJumpLastChild ." :call <SID>JumpToLastChild()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapJumpLastChild ." :call <SID>JumpToLastChild()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapJumpRoot ." :call <SID>JumpToRoot()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapJumpRoot ." :call <SID>JumpToRoot()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTab ." :call <SID>OpenNodeNewTab(0)<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTab ." :call <SID>OpenInNewTab(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTabSilent ." :call <SID>OpenNodeNewTab(1)<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenInTabSilent ." :call <SID>OpenInNewTab(1)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenExpl ." :call <SID>OpenExplorer()<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenExpl ." :call <SID>OpenExplorer()<cr>"
command! -buffer -nargs=1 Bookmark :call <SID>BookmarkNode('<args>') 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:CompleteBookmarks -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:CompleteBookmarks -nargs=1 OpenBookmark :call <SID>OpenBookmark('<args>')
command! -buffer -complete=customlist,s:FindBookmarks -nargs=* ClearBookmarks call <SID>ClearBookmarks('<args>') command! -buffer -complete=customlist,s:CompleteBookmarks -nargs=* ClearBookmarks call <SID>ClearBookmarks('<args>')
command! -buffer -complete=customlist,s:FindBookmarks -nargs=+ BookmarkToRoot call <SID>BookmarkToRoot('<args>') command! -buffer -complete=customlist,s:CompleteBookmarks -nargs=+ BookmarkToRoot call <SID>BookmarkToRoot('<args>')
command! -buffer -nargs=0 ClearAllBookmarks call <SID>ClearAllBookmarks() <bar> call <SID>RenderView() command! -buffer -nargs=0 ClearAllBookmarks call s:oBookmark.ClearAll() <bar> call <SID>RenderView()
command! -buffer -nargs=0 ReadBookmarks call <SID>ReadBookmarks() <bar> call <SID>RenderView() command! -buffer -nargs=0 ReadBookmarks call s:oBookmark.CacheBookmarks() <bar> call <SID>RenderView()
command! -buffer -nargs=0 WriteBookmarks call <SID>WriteBookmarks() command! -buffer -nargs=0 WriteBookmarks call s:oBookmark.Write()
endfunction endfunction
" FUNCTION: s:BookmarkNode(name) {{{2 " FUNCTION: s:BookmarkNode(name) {{{2
" Associate the current node with the given name " Associate the current node with the given name
function! s:BookmarkNode(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() let currentNode = s:GetSelectedNode()
if currentNode != {} if currentNode != {}
try try
let oldMarkedNode = s:GetNodeForBookmark(a:name, 1) call currentNode.Bookmark(a:name)
call oldMarkedNode.path.UncacheBookmark(a:name) call s:RenderView()
catch /NERDTree.Bookmark\(DoesntExist\|NotFound\)/ catch /NERDTree.IllegalBookmarkName/
call s:Echo("bookmark names must not contain spaces")
endtry endtry
let bookmarks = s:GetBookmarks()
let bookmarks[a:name] = currentNode.path
call currentNode.path.CacheBookmarkNames()
call s:WriteBookmarks()
call s:RenderView()
else else
call s:Echo("select a node first") call s:Echo("select a node first")
endif endif
@@ -2649,10 +2811,9 @@ endfunction
" Make the node for the given bookmark the new tree root " Make the node for the given bookmark the new tree root
function! s:BookmarkToRoot(name) function! s:BookmarkToRoot(name)
try try
let targetNode = s:GetNodeForBookmark(a:name, 1) let targetNode = s:oBookmark.GetNodeForName(a:name, 1)
catch /NERDTree.BookmarkNotFound/ catch /NERDTree.BookmarkNotFound/
let bookmarks = s:GetBookmarks() let targetNode = s:oTreeFileNode.New(s:oBookmark.BookmarkFor(a:name).path)
let targetNode = s:oTreeFileNode.New(bookmarks[a:name])
endtry endtry
call targetNode.MakeRoot() call targetNode.MakeRoot()
call s:RenderView() call s:RenderView()
@@ -2718,7 +2879,6 @@ endfunction
" FUNCTION: s:ClearBookmarks(bookmarks) {{{2 " FUNCTION: s:ClearBookmarks(bookmarks) {{{2
function! s:ClearBookmarks(bookmarks) function! s:ClearBookmarks(bookmarks)
let bookmarks = s:GetBookmarks()
if a:bookmarks == '' if a:bookmarks == ''
let currentNode = s:GetSelectedNode() let currentNode = s:GetSelectedNode()
if currentNode != {} if currentNode != {}
@@ -2726,20 +2886,11 @@ function! s:ClearBookmarks(bookmarks)
endif endif
else else
for name in split(a:bookmarks, ' ') for name in split(a:bookmarks, ' ')
if count(keys(bookmarks), name) let bookmark = s:oBookmark.BookmarkFor(name)
let node = {} call bookmark.Delete()
try
let node = s:GetNodeForBookmark(name, 1)
catch /NERDTree/
endtry
call remove(bookmarks, name)
if !empty(node)
call node.path.CacheBookmarkNames()
endif
endif
endfor endfor
endif endif
call s:WriteBookmarks() call s:oBookmark.Write()
call s:RenderView() call s:RenderView()
endfunction endfunction
" FUNCTION: s:CloseChildren() {{{2 " FUNCTION: s:CloseChildren() {{{2
@@ -2793,7 +2944,7 @@ function! s:CopyNode()
let confirmed = 1 let confirmed = 1
if currentNode.path.CopyingWillOverwrite(newNodePath) if currentNode.path.CopyingWillOverwrite(newNodePath)
echo "\nWarning: copying may overwrite files! Continue? (yN)" call s:Echo("\nWarning: copying may overwrite files! Continue? (yN)")
let choice = nr2char(getchar()) let choice = nr2char(getchar())
let confirmed = choice == 'y' let confirmed = choice == 'y'
endif endif
@@ -3001,13 +3152,13 @@ endfunction
" put the cursor on the given bookmark and, if its a file, open it " put the cursor on the given bookmark and, if its a file, open it
function! s:OpenBookmark(name) function! s:OpenBookmark(name)
try try
let targetNode = s:GetNodeForBookmark(a:name, 0) let targetNode = s:oBookmark.GetNodeForName(a:name, 0)
call s:PutCursorOnNode(targetNode, 0, 1) call s:PutCursorOnNode(targetNode, 0, 1)
redraw! redraw!
catch /NERDTree.BookmarkNotFound/ catch /NERDTree.BookmarkNotFound/
call s:Echo("note - target node is not cached") call s:Echo("note - target node is not cached")
let bookmarks = s:GetBookmarks() let bookmark = s:oBookmark.BookmarkFor(a:name)
let targetNode = s:oTreeFileNode.New(bookmarks[a:name]) let targetNode = s:oTreeFileNode.New(bookmark.path)
endtry endtry
if targetNode.path.isDirectory if targetNode.path.isDirectory
call s:OpenExplorerFor(targetNode) call s:OpenExplorerFor(targetNode)
@@ -3022,6 +3173,9 @@ function! s:OpenEntrySplit()
let treenode = s:GetSelectedNode() let treenode = s:GetSelectedNode()
if treenode != {} if treenode != {}
call s:OpenFileNodeSplit(treenode) call s:OpenFileNodeSplit(treenode)
if g:NERDTreeQuitOnOpen
call s:CloseTree()
endif
else else
call s:Echo("select a node first") call s:Echo("select a node first")
endif endif
@@ -3037,27 +3191,35 @@ function! s:OpenExplorer()
endif endif
endfunction endfunction
" FUNCTION: s:OpenNodeNewTab(stayCurrentTab) {{{2 " FUNCTION: s:OpenInNewTab(stayCurrentTab) {{{2
" Opens the currently selected file from the explorer in a " Opens the selected node or bookmark in a new tab
" new tab
"
" Args: " Args:
" stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim " stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim
" will go to the tab where the new file is opened " will go to the tab where the new file is opened
function! s:OpenNodeNewTab(stayCurrentTab) function! s:OpenInNewTab(stayCurrentTab)
let currentTab = tabpagenr()
let treenode = s:GetSelectedNode() let treenode = s:GetSelectedNode()
if treenode != {} if treenode != {}
let curTabNr = tabpagenr()
exec "tabedit " . treenode.path.StrForEditCmd() exec "tabedit " . treenode.path.StrForEditCmd()
if a:stayCurrentTab if a:stayCurrentTab
exec "tabnext " . curTabNr exec "tabnext " . currentTab
endif endif
else else
call s:Echo("select a node first") let bookmark = s:GetSelectedBookmark()
if bookmark != {}
if bookmark.path.isDirectory
exec "tabnew +NERDTreeFromBookmark\\ " . bookmark.name
else
exec "tabedit " . bookmark.path.StrForEditCmd()
endif
if a:stayCurrentTab
exec "tabnext " . currentTab
endif
endif
endif endif
endfunction endfunction
" FUNCTION: s:OpenNodeRecursively() {{{2 " FUNCTION: s:OpenNodeRecursively() {{{2
function! s:OpenNodeRecursively() function! s:OpenNodeRecursively()
let treenode = s:GetSelectedNode() let treenode = s:GetSelectedNode()
@@ -3093,7 +3255,7 @@ endfunction
" put the cursor on the node associate with the given name " put the cursor on the node associate with the given name
function! s:RevealBookmark(name) function! s:RevealBookmark(name)
try try
let targetNode = s:GetNodeForBookmark(a:name, 0) let targetNode = s:oBookmark.GetNodeForName(a:name, 0)
call s:PutCursorOnNode(targetNode, 0, 1) call s:PutCursorOnNode(targetNode, 0, 1)
catch /NERDTree.BookmarkDoesntExist/ catch /NERDTree.BookmarkDoesntExist/
call s:Echo("Bookmark isnt cached under the current root") call s:Echo("Bookmark isnt cached under the current root")
@@ -3209,10 +3371,17 @@ function! s:ToggleIgnoreFilter()
call s:CenterView() call s:CenterView()
endfunction endfunction
" FUNCTION: s:ToggleShowBookmarks() {{{2
" toggles the display of bookmarks
function! s:ToggleShowBookmarks()
let t:NERDTreeShowBookmarks = !t:NERDTreeShowBookmarks
call s:RenderViewSavingPosition()
call s:CenterView()
endfunction
" FUNCTION: s:ToggleShowFiles() {{{2 " FUNCTION: s:ToggleShowFiles() {{{2
" toggles the display of hidden files " toggles the display of hidden files
function! s:ToggleShowFiles() function! s:ToggleShowFiles()
let g:NERDTreeShowFiles = !g:NERDTreeShowFiles let t:NERDTreeShowFiles = !t:NERDTreeShowFiles
call s:RenderViewSavingPosition() call s:RenderViewSavingPosition()
call s:CenterView() call s:CenterView()
endfunction endfunction
@@ -3220,7 +3389,7 @@ endfunction
" FUNCTION: s:ToggleShowHidden() {{{2 " FUNCTION: s:ToggleShowHidden() {{{2
" toggles the display of hidden files " toggles the display of hidden files
function! s:ToggleShowHidden() function! s:ToggleShowHidden()
let g:NERDTreeShowHidden = !g:NERDTreeShowHidden let t:NERDTreeShowHidden = !t:NERDTreeShowHidden
call s:RenderViewSavingPosition() call s:RenderViewSavingPosition()
call s:CenterView() call s:CenterView()
endfunction endfunction