dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

commit f8e71ba098e48dee9c45f97b02409f222720bb48
parent 320b4ebc35eb9d108b03a85e63b25d1168d203d5
Author: Chris Bracken <cbracken@google.com>
Date:   Wed, 28 Mar 2012 12:53:51 -0700

Upgraded NERD Tree to version 4.2.0

Diffstat:
M.vim/doc/NERD_tree.txt | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
M.vim/nerdtree_plugin/fs_menu.vim | 44+++++++++++++++++++++++++++++++++++++-------
M.vim/plugin/NERD_tree.vim | 396+++++++++++++++++++++++++++++++++++--------------------------------------------
A.vim/syntax/nerdtree.vim | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 374 insertions(+), 229 deletions(-)

diff --git a/.vim/doc/NERD_tree.txt b/.vim/doc/NERD_tree.txt @@ -129,9 +129,13 @@ The following features and functionality are provided by the NERD tree: Close the NERD tree in this tab. :NERDTreeFind *:NERDTreeFind* - Find the current file in the tree. If no tree exists for the current tab, - or the file is not under the current root, then initialize a new tree where - the root is the directory of the current file. + Find the current file in the tree. + + If not tree exists and the current file is under vim's CWD, then init a + tree at the CWD and reveal the file. Otherwise init a tree in the current + file's directory. + + In any case, the current file is revealed and the cursor is placed on it. ------------------------------------------------------------------------------ 2.2. Bookmarks *NERDTreeBookmarks* @@ -155,6 +159,8 @@ 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 not contain spaces. + If <name> is not provided, it defaults to the file or directory name. + For directories, a trailing slash is present. :BookmarkToRoot <bookmark> Make the directory corresponding to <bookmark> the new root. If a treenode @@ -642,6 +648,12 @@ NERD tree. These options should be set in your vimrc. |'NERDTreeWinSize'| Sets the window size when the NERD tree is opened. +|'NERDTreeMinimalUI'| Disables display of the 'Bookmarks' label and + 'Press ? for help' text. + +|'NERDTreeDirArrows'| Tells the NERD tree to use arrows instead of + + ~ chars when displaying directories. + ------------------------------------------------------------------------------ 3.2. Customisation details *NERDTreeOptionDetails* @@ -921,6 +933,30 @@ Default: 31. This option is used to change the size of the NERD tree when it is loaded. +------------------------------------------------------------------------------ + *'NERDTreeMinimalUI'* +Values: 0 or 1 +Default: 0 + +This options disables the 'Bookmarks' label 'Press ? for help' text. Use one +of the following lines to set this option: > + let NERDTreeMinimalUI=0 + let NERDTreeMinimalUI=1 +< + +------------------------------------------------------------------------------ + *'NERDTreeDirArrows'* +Values: 0 or 1 +Default: 0. + +This option is used to change the default look of directory nodes displayed in +the tree. When set to 0 it shows old-school bars (|), + and ~ chars. If set to +1 it shows right and down arrows. Use one of the follow lines to set this +option: > + let NERDTreeDirArrows=0 + let NERDTreeDirArrows=1 +< + ============================================================================== 4. The NERD tree API *NERDTreeAPI* @@ -1080,6 +1116,23 @@ The latest dev versions are on github ============================================================================== 6. Changelog *NERDTreeChangelog* +4.2.0 + - Add NERDTreeDirArrows option to make the UI use pretty arrow chars + instead of the old +~| chars to define the tree structure (sickill) + - shift the syntax highlighting out into its own syntax file (gnap) + - add some mac specific options to the filesystem menu - for macvim + only (andersonfreitas) + - Add NERDTreeMinimalUI option to remove some non functional parts of the + nerdtree ui (camthompson) + - tweak the behaviour of :NERDTreeFind - see :help :NERDTreeFind for the + new behaviour (benjamingeiger) + - if no name is given to :Bookmark, make it default to the name of the + target file/dir (minyoung) + - use 'file' completion when doing copying, create, and move + operations (EvanDotPro) + - lots of misc bug fixes (paddyoloughlin, sdewald, camthompson, Vitaly + Bogdanov, AndrewRadev, mathias, scottstvnsn, kml, wycats, me RAWR!) + 4.1.0 features: - NERDTreeFind to reveal the node for the current buffer in the tree, @@ -1214,6 +1267,22 @@ just downloaded pr0n instead. Ricky jfilip1024 Chris Chambers + Vitaly Bogdanov + Patrick O'Loughlin (paddyoloughlin) + Cam Thompson (camthompson) + Marcin Kulik (sickill) + Steve DeWald (sdewald) + Ivan Necas (iNecas) + George Ang (gnap) + Evan Coury (EvanDotPro) + Andrew Radev (AndrewRadev) + Matt Gauger (mathias) + Scott Stevenson (scottstvnsn) + Anderson Freitas (andersonfreitas) + Kamil K. Lemański (kml) + Yehuda Katz (wycats) + Min-Young Wu (minyoung) + Benjamin Geiger (benjamingeiger) ============================================================================== 8. License *NERDTreeLicense* diff --git a/.vim/nerdtree_plugin/fs_menu.vim b/.vim/nerdtree_plugin/fs_menu.vim @@ -16,8 +16,15 @@ endif let g:loaded_nerdtree_fs_menu = 1 call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callback': 'NERDTreeAddNode'}) -call NERDTreeAddMenuItem({'text': '(m)ove the curent node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'}) -call NERDTreeAddMenuItem({'text': '(d)elete the curent node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'}) +call NERDTreeAddMenuItem({'text': '(m)ove the current node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'}) +call NERDTreeAddMenuItem({'text': '(d)elete the current node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'}) + +if has("gui_mac") || has("gui_macvim") + call NERDTreeAddMenuItem({'text': '(r)eveal in Finder the current node', 'shortcut': 'r', 'callback': 'NERDTreeRevealInFinder'}) + call NERDTreeAddMenuItem({'text': '(o)pen the current node with system editor', 'shortcut': 'o', 'callback': 'NERDTreeExecuteFile'}) + call NERDTreeAddMenuItem({'text': '(q)uicklook the current node', 'shortcut': 'q', 'callback': 'NERDTreeQuickLook'}) +endif + if g:NERDTreePath.CopyingSupported() call NERDTreeAddMenuItem({'text': '(c)copy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'}) endif @@ -57,7 +64,7 @@ function! NERDTreeAddNode() let newNodeName = input("Add a childnode\n". \ "==========================================================\n". \ "Enter the dir/file name to be created. Dirs end with a '/'\n" . - \ "", curDirNode.path.str({'format': 'Glob'}) . g:NERDTreePath.Slash()) + \ "", curDirNode.path.str() . g:NERDTreePath.Slash(), "file") if newNodeName ==# '' call s:echo("Node Creation Aborted.") @@ -85,7 +92,7 @@ function! NERDTreeMoveNode() let newNodePath = input("Rename the current node\n" . \ "==========================================================\n" . \ "Enter the new path for the node: \n" . - \ "", curNode.path.str()) + \ "", curNode.path.str(), "file") if newNodePath ==# '' call s:echo("Node Renaming Aborted.") @@ -163,7 +170,7 @@ function! NERDTreeCopyNode() let newNodePath = input("Copy the current node\n" . \ "==========================================================\n" . \ "Enter the new path to copy the node to: \n" . - \ "", currentNode.path.str()) + \ "", currentNode.path.str(), "file") if newNodePath != "" "strip trailing slash @@ -179,8 +186,10 @@ function! NERDTreeCopyNode() if confirmed try let newNode = currentNode.copy(newNodePath) - call NERDTreeRender() - call newNode.putCursorHere(0, 0) + if !empty(newNode) + call NERDTreeRender() + call newNode.putCursorHere(0, 0) + endif catch /^NERDTree/ call s:echoWarning("Could not copy node") endtry @@ -191,4 +200,25 @@ function! NERDTreeCopyNode() redraw endfunction +function! NERDTreeQuickLook() + let treenode = g:NERDTreeFileNode.GetSelected() + if treenode != {} + call system("qlmanage -p 2>/dev/null '" . treenode.path.str() . "'") + endif +endfunction + +function! NERDTreeRevealInFinder() + let treenode = g:NERDTreeFileNode.GetSelected() + if treenode != {} + let x = system("open -R '" . treenode.path.str() . "'") + endif +endfunction + +function! NERDTreeExecuteFile() + let treenode = g:NERDTreeFileNode.GetSelected() + if treenode != {} + let x = system("open '" . treenode.path.str() . "'") + endif +endfunction + " vim: set sw=4 sts=4 et fdm=marker: diff --git a/.vim/plugin/NERD_tree.vim b/.vim/plugin/NERD_tree.vim @@ -2,7 +2,7 @@ " File: NERD_tree.vim " Description: vim global plugin that provides a nice tree explorer " Maintainer: Martin Grenfell <martin.grenfell at gmail dot com> -" Last Change: 1 December, 2009 +" Last Change: 28 December, 2011 " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -10,7 +10,7 @@ " See http://sam.zoy.org/wtfpl/COPYING for more details. " " ============================================================================ -let s:NERD_tree_version = '4.1.0' +let s:NERD_tree_version = '4.2.0' " SECTION: Script init stuff {{{1 "============================================================ @@ -27,6 +27,8 @@ let loaded_nerd_tree = 1 let s:old_cpo = &cpo set cpo&vim +let s:running_windows = has("win16") || has("win32") || has("win64") + "Function: s:initVariable() function {{{2 "This function is used to initialise a given variable to a given value. The "variable is only initialised if it does not exist prior @@ -39,7 +41,7 @@ set cpo&vim "1 if the var is set, 0 otherwise function! s:initVariable(var, value) if !exists(a:var) - exec 'let ' . a:var . ' = ' . "'" . a:value . "'" + exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'" return 1 endif return 0 @@ -51,6 +53,7 @@ call s:initVariable("g:NERDTreeAutoCenter", 1) call s:initVariable("g:NERDTreeAutoCenterThreshold", 3) call s:initVariable("g:NERDTreeCaseSensitiveSort", 0) call s:initVariable("g:NERDTreeChDirMode", 0) +call s:initVariable("g:NERDTreeMinimalUI", 0) if !exists("g:NERDTreeIgnore") let g:NERDTreeIgnore = ['\~$'] endif @@ -65,6 +68,7 @@ call s:initVariable("g:NERDTreeShowFiles", 1) call s:initVariable("g:NERDTreeShowHidden", 0) call s:initVariable("g:NERDTreeShowLineNumbers", 0) call s:initVariable("g:NERDTreeSortDirs", 1) +call s:initVariable("g:NERDTreeDirArrows", !s:running_windows) if !exists("g:NERDTreeSortOrder") let g:NERDTreeSortOrder = ['\/$', '*', '\.swp$', '\.bak$', '\~$'] @@ -90,8 +94,6 @@ endif call s:initVariable("g:NERDTreeWinPos", "left") call s:initVariable("g:NERDTreeWinSize", 31) -let s:running_windows = has("win16") || has("win32") || has("win64") - "init the shell commands that will be used to copy nodes, and remove dir trees " "Note: the space after the command is important @@ -142,12 +144,12 @@ call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U") if s:running_windows let s:escape_chars = " `\|\"#%&,?()\*^<>" else - let s:escape_chars = " \\`\|\"#%&,?()\*^<>" + let s:escape_chars = " \\`\|\"#%&,?()\*^<>[]" endif let s:NERDTreeBufName = 'NERD_tree_' let s:tree_wid = 2 -let s:tree_markup_reg = '^[ `|]*[\-+~]' +let s:tree_markup_reg = '^[ `|]*[\-+~▾▸ ]\+' let s:tree_up_dir_line = '.. (up a dir)' "the number to add to the nerd tree buffer name to make the buf name unique @@ -167,6 +169,10 @@ command! -n=0 -bar NERDTreeFind call s:findAndRevealPath() augroup NERDTree "Save the cursor position whenever we close the nerd tree exec "autocmd BufWinLeave ". s:NERDTreeBufName ."* call <SID>saveScreenState()" + + "disallow insert mode in the NERDTree + exec "autocmd BufEnter ". s:NERDTreeBufName ."* stopinsert" + "cache bookmarks when vim loads autocmd VimEnter * call s:Bookmark.CacheBookmarks(0) @@ -194,6 +200,7 @@ function! s:Bookmark.activate() if self.validate() let n = s:TreeFileNode.New(self.path) call n.open() + call s:closeTreeIfQuitOnOpen() endif endif endfunction @@ -372,7 +379,7 @@ endfunction " FUNCTION: Bookmark.New(name, path) {{{3 " Create a new bookmark object with the given name and path object function! s:Bookmark.New(name, path) - if a:name =~ ' ' + if a:name =~# ' ' throw "NERDTree.IllegalBookmarkNameError: illegal name:" . a:name endif @@ -389,7 +396,7 @@ function! s:Bookmark.openInNewTab(options) tabnew call s:initNerdTree(self.name) else - exec "tabedit " . bookmark.path.str({'format': 'Edit'}) + exec "tabedit " . self.path.str({'format': 'Edit'}) endif if has_key(a:options, 'stayInCurrentTab') @@ -558,7 +565,7 @@ function! s:MenuController._echoPrompt() endfunction "FUNCTION: MenuController._current(key) {{{3 -"get the MenuItem that is curently selected +"get the MenuItem that is currently selected function! s:MenuController._current() return self.menuItems[self.selection] endfunction @@ -806,15 +813,23 @@ endfunction "FUNCTION: TreeFileNode.bookmark(name) {{{3 "bookmark this node with a:name function! s:TreeFileNode.bookmark(name) + + "if a bookmark exists with the same name and the node is cached then save + "it so we can update its display string + let oldMarkedNode = {} try let oldMarkedNode = s:Bookmark.GetNodeForName(a:name, 1) - call oldMarkedNode.path.cacheDisplayString() catch /^NERDTree.BookmarkNotFoundError/ + catch /^NERDTree.BookmarkedNodeNotFoundError/ endtry call s:Bookmark.AddBookmark(a:name, self.path) call self.path.cacheDisplayString() call s:Bookmark.Write() + + if !empty(oldMarkedNode) + call oldMarkedNode.path.cacheDisplayString() + endif endfunction "FUNCTION: TreeFileNode.cacheParent() {{{3 "initializes self.parent if it isnt already @@ -855,8 +870,10 @@ function! s:TreeFileNode.copy(dest) let parent = b:NERDTreeRoot.findNode(newPath.getParent()) if !empty(parent) call parent.refresh() + return parent.findNode(newPath) + else + return {} endif - return parent.findNode(newPath) endfunction "FUNCTION: TreeFileNode.delete {{{3 @@ -1028,7 +1045,7 @@ endfunction "gets the line number of the root node function! s:TreeFileNode.GetRootLineNum() let rootLine = 1 - while getline(rootLine) !~ '^\(/\|<\)' + while getline(rootLine) !~# '^\(/\|<\)' let rootLine = rootLine + 1 endwhile return rootLine @@ -1304,33 +1321,50 @@ function! s:TreeFileNode._renderToString(depth, drawText, vertMap, isLastChild) "get all the leading spaces and vertical tree parts for this line if a:depth > 1 for j in a:vertMap[0:-2] - if j ==# 1 - let treeParts = treeParts . '| ' - else + if g:NERDTreeDirArrows let treeParts = treeParts . ' ' + else + if j ==# 1 + let treeParts = treeParts . '| ' + else + let treeParts = treeParts . ' ' + endif endif endfor endif "get the last vertical tree part for this line which will be different "if this node is the last child of its parent - if a:isLastChild - let treeParts = treeParts . '`' - else - let treeParts = treeParts . '|' + if !g:NERDTreeDirArrows + if a:isLastChild + let treeParts = treeParts . '`' + else + let treeParts = treeParts . '|' + endif endif - "smack the appropriate dir/file symbol on the line before the file/dir "name itself if self.path.isDirectory if self.isOpen - let treeParts = treeParts . '~' + if g:NERDTreeDirArrows + let treeParts = treeParts . '▾ ' + else + let treeParts = treeParts . '~' + endif else - let treeParts = treeParts . '+' + if g:NERDTreeDirArrows + let treeParts = treeParts . '▸ ' + else + let treeParts = treeParts . '+' + endif endif else - let treeParts = treeParts . '-' + if g:NERDTreeDirArrows + let treeParts = treeParts . ' ' + else + let treeParts = treeParts . '-' + endif endif let line = treeParts . self.displayString() @@ -1593,7 +1627,7 @@ function! s:TreeDirNode._initChildren(silent) "filter out the .. and . directories "Note: we must match .. AND ../ cos sometimes the globpath returns "../ for path with strange chars (eg $) - if i !~ '\/\.\.\/\?$' && i !~ '\/\.\/\?$' + if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' "put the next file in a new node and attach it try @@ -1730,7 +1764,7 @@ function! s:TreeDirNode.refresh() "filter out the .. and . directories "Note: we must match .. AND ../ cos sometimes the globpath returns "../ for path with strange chars (eg $) - if i !~ '\/\.\.\/\?$' && i !~ '\/\.\/\?$' + if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$' try "create a new path and see if it exists in this nodes children @@ -1852,9 +1886,9 @@ let s:Path = {} function! s:Path.AbsolutePathFor(str) let prependCWD = 0 if s:running_windows - let prependCWD = a:str !~ '^.:\(\\\|\/\)' + let prependCWD = a:str !~# '^.:\(\\\|\/\)' else - let prependCWD = a:str !~ '^/' + let prependCWD = a:str !~# '^/' endif let toReturn = a:str @@ -1971,7 +2005,7 @@ function! s:Path.Create(fullpath) try "if it ends with a slash, assume its a dir create it - if a:fullpath =~ '\(\\\|\/\)$' + if a:fullpath =~# '\(\\\|\/\)$' "whack the trailing slash off the end if it exists let fullpath = substitute(a:fullpath, '\(\\\|\/\)$', '', '') @@ -2001,7 +2035,7 @@ function! s:Path.copy(dest) let dest = s:Path.WinToUnixPath(a:dest) - let cmd = g:NERDTreeCopyCmd . " " . self.str() . " " . dest + let cmd = g:NERDTreeCopyCmd . " " . escape(self.str(), s:escape_chars) . " " . escape(dest, s:escape_chars) let success = system(cmd) if success != 0 throw "NERDTree.CopyError: Could not copy ''". self.str() ."'' to: '" . a:dest . "'" @@ -2144,7 +2178,7 @@ endfunction function! s:Path.getSortOrderIndex() let i = 0 while i < len(g:NERDTreeSortOrder) - if self.getLastPathComponent(1) =~ g:NERDTreeSortOrder[i] + if self.getLastPathComponent(1) =~# g:NERDTreeSortOrder[i] return i endif let i = i + 1 @@ -2160,14 +2194,14 @@ function! s:Path.ignore() "filter out the user specified paths to ignore if b:NERDTreeIgnoreEnabled for i in g:NERDTreeIgnore - if lastPathComponent =~ i + if lastPathComponent =~# i return 1 endif endfor endif "dont show hidden files unless instructed to - if b:NERDTreeShowHidden ==# 0 && lastPathComponent =~ '^\.' + if b:NERDTreeShowHidden ==# 0 && lastPathComponent =~# '^\.' return 1 endif @@ -2257,7 +2291,7 @@ function! s:Path.readInfoFromDisk(fullpath) let self.isExecutable = 0 if !self.isDirectory - let self.isExecutable = getfperm(a:fullpath) =~ 'x' + let self.isExecutable = getfperm(a:fullpath) =~# 'x' endif "grab the last part of the path (minus the trailing slash) @@ -2276,7 +2310,7 @@ function! s:Path.readInfoFromDisk(fullpath) "we always wanna treat MS windows shortcuts as files for "simplicity - if hardPath !~ '\.lnk$' + if hardPath !~# '\.lnk$' let self.symLinkDest = self.symLinkDest . '/' endif @@ -2508,7 +2542,7 @@ endfunction " FUNCTION: s:completeBookmarks(A,L,P) {{{2 " completion function for the bookmark commands function! s:completeBookmarks(A,L,P) - return filter(s:Bookmark.BookmarkNames(), 'v:val =~ "^' . a:A . '"') + return filter(s:Bookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"') endfunction " FUNCTION: s:exec(cmd) {{{2 " same as :exec cmd but eventignore=all is set for the duration @@ -2521,14 +2555,25 @@ endfunction " FUNCTION: s:findAndRevealPath() {{{2 function! s:findAndRevealPath() try - let p = s:Path.New(expand("%")) + let p = s:Path.New(expand("%:p")) catch /^NERDTree.InvalidArgumentsError/ call s:echo("no file for the current buffer") return endtry if !s:treeExistsForTab() - call s:initNerdTree(p.getParent().str()) + try + let cwd = s:Path.New(getcwd()) + catch /^NERDTree.InvalidArgumentsError/ + call s:echo("current directory does not exist.") + let cwd = p.getParent() + endtry + + if p.isUnder(cwd) + call s:initNerdTree(cwd.str()) + else + call s:initNerdTree(p.getParent().str()) + endif else if !p.isUnder(s:TreeFileNode.GetRootForTab().path) call s:initNerdTree(p.getParent().str()) @@ -2555,7 +2600,7 @@ function! s:initNerdTree(name) let dir = a:name ==# '' ? getcwd() : a:name "hack to get an absolute path if a relative path is given - if dir =~ '^\.' + if dir =~# '^\.' let dir = getcwd() . s:Path.Slash() . dir endif let dir = resolve(dir) @@ -2624,43 +2669,9 @@ function! s:initNerdTreeInPlace(dir) let b:NERDTreeRoot = s:TreeDirNode.New(path) call b:NERDTreeRoot.open() - "throwaway buffer options - setlocal noswapfile - setlocal buftype=nofile - setlocal bufhidden=hide - setlocal nowrap - setlocal foldcolumn=0 - setlocal nobuflisted - setlocal nospell - if g:NERDTreeShowLineNumbers - setlocal nu - else - setlocal nonu - endif - - iabc <buffer> - - if g:NERDTreeHighlightCursorline - setlocal cursorline - endif - - call s:setupStatusline() - - let b:treeShowHelp = 0 - let b:NERDTreeIgnoreEnabled = 1 - let b:NERDTreeShowFiles = g:NERDTreeShowFiles - let b:NERDTreeShowHidden = g:NERDTreeShowHidden - let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks - + call s:setCommonBufOptions() let b:NERDTreeType = "secondary" - call s:bindMappings() - setfiletype nerdtree - " syntax highlighting - if has("syntax") && exists("g:syntax_on") - call s:setupSyntaxHighlighting() - endif - call s:renderView() endfunction " FUNCTION: s:initNerdTreeMirror() {{{2 @@ -2812,9 +2823,17 @@ function! s:closeTree() endif if winnr("$") != 1 + if winnr() == s:getTreeWinNum() + wincmd p + let bufnr = bufnr("") + wincmd p + else + let bufnr = bufnr("") + endif + call s:exec(s:getTreeWinNum() . " wincmd w") close - call s:exec("wincmd p") + call s:exec(bufwinnr(bufnr) . " wincmd w") else close endif @@ -2852,34 +2871,7 @@ function! s:createTreeWin() endif setlocal winfixwidth - - "throwaway buffer options - setlocal noswapfile - setlocal buftype=nofile - setlocal nowrap - setlocal foldcolumn=0 - setlocal nobuflisted - setlocal nospell - if g:NERDTreeShowLineNumbers - setlocal nu - else - setlocal nonu - endif - - iabc <buffer> - - if g:NERDTreeHighlightCursorline - setlocal cursorline - endif - - call s:setupStatusline() - - call s:bindMappings() - setfiletype nerdtree - " syntax highlighting - if has("syntax") && exists("g:syntax_on") - call s:setupSyntaxHighlighting() - endif + call s:setCommonBufOptions() endfunction "FUNCTION: s:dumpHelp {{{2 @@ -2979,12 +2971,12 @@ function! s:dumpHelp() let @h=@h."\" :OpenBookmark <name>\n" let @h=@h."\" :ClearBookmarks [<names>]\n" let @h=@h."\" :ClearAllBookmarks\n" - else + silent! put h + elseif g:NERDTreeMinimalUI == 0 let @h="\" Press ". g:NERDTreeMapHelp ." for help\n" + silent! put h endif - silent! put h - let @h = old_h endfunction "FUNCTION: s:echo {{{2 @@ -3050,9 +3042,11 @@ function! s:getPath(ln) return b:NERDTreeRoot.path endif - " in case called from outside the tree - if line !~ '^ *[|`]' || line =~ '^$' - return {} + if !g:NERDTreeDirArrows + " in case called from outside the tree + if line !~# '^ *[|`▸▾ ]' || line =~# '^$' + return {} + endif endif if line ==# s:tree_up_dir_line @@ -3065,7 +3059,7 @@ function! s:getPath(ln) let curFile = s:stripMarkupFromLine(line, 0) let wasdir = 0 - if curFile =~ '/$' + if curFile =~# '/$' let wasdir = 1 let curFile = substitute(curFile, '/\?$', '/', "") endif @@ -3082,7 +3076,7 @@ function! s:getPath(ln) let dir = b:NERDTreeRoot.path.str({'format': 'UI'}) . dir break endif - if curLineStripped =~ '/$' + if curLineStripped =~# '/$' let lpindent = s:indentLevelFor(curLine) if lpindent < indent let indent = indent - 1 @@ -3108,7 +3102,13 @@ function! s:getTreeWinNum() endfunction "FUNCTION: s:indentLevelFor(line) {{{2 function! s:indentLevelFor(line) - return match(a:line, '[^ \-+~`|]') / s:tree_wid + let level = match(a:line, '[^ \-+~▸▾`|]') / s:tree_wid + " check if line includes arrows + if match(a:line, '[▸▾]') > -1 + " decrement level as arrow uses 3 ascii chars + let level = level - 1 + endif + return level endfunction "FUNCTION: s:isTreeOpen() {{{2 function! s:isTreeOpen() @@ -3198,16 +3198,20 @@ function! s:putCursorOnBookmarkTable() throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active" endif + if g:NERDTreeMinimalUI + return cursor(1, 2) + endif + let rootNodeLine = s:TreeFileNode.GetRootLineNum() let line = 1 - while getline(line) !~ '^>-\+Bookmarks-\+$' + while getline(line) !~# '^>-\+Bookmarks-\+$' let line = line + 1 if line >= rootNodeLine throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table" endif endwhile - call cursor(line, 0) + call cursor(line, 2) endfunction "FUNCTION: s:putCursorInTreeWin(){{{2 @@ -3223,8 +3227,10 @@ endfunction "FUNCTION: s:renderBookmarks {{{2 function! s:renderBookmarks() - call setline(line(".")+1, ">----------Bookmarks----------") - call cursor(line(".")+1, col(".")) + if g:NERDTreeMinimalUI == 0 + call setline(line(".")+1, ">----------Bookmarks----------") + call cursor(line(".")+1, col(".")) + endif for i in s:Bookmark.Bookmarks() call setline(line(".")+1, i.str()) @@ -3251,16 +3257,20 @@ function! s:renderView() call s:dumpHelp() "delete the blank line before the help and add one after it - call setline(line(".")+1, "") - call cursor(line(".")+1, col(".")) + if g:NERDTreeMinimalUI == 0 + call setline(line(".")+1, "") + call cursor(line(".")+1, col(".")) + endif if b:NERDTreeShowBookmarks call s:renderBookmarks() endif "add the 'up a dir' line - call setline(line(".")+1, s:tree_up_dir_line) - call cursor(line(".")+1, col(".")) + if !g:NERDTreeMinimalUI + call setline(line(".")+1, s:tree_up_dir_line) + call cursor(line(".")+1, col(".")) + endif "draw the header line let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)}) @@ -3340,103 +3350,49 @@ function! s:saveScreenState() endtry endfunction -"FUNCTION: s:setupStatusline() {{{2 -function! s:setupStatusline() - if g:NERDTreeStatusline != -1 - let &l:statusline = g:NERDTreeStatusline - endif -endfunction -"FUNCTION: s:setupSyntaxHighlighting() {{{2 -function! s:setupSyntaxHighlighting() - "treeFlags are syntax items that should be invisible, but give clues as to - "how things should be highlighted - syn match treeFlag #\~# - syn match treeFlag #\[RO\]# - - "highlighting for the .. (up dir) line at the top of the tree - execute "syn match treeUp #". s:tree_up_dir_line ."#" - - "highlighting for the ~/+ symbols for the directory nodes - syn match treeClosable #\~\<# - syn match treeClosable #\~\.# - syn match treeOpenable #+\<# - syn match treeOpenable #+\.#he=e-1 - - "highlighting for the tree structural parts - syn match treePart #|# - syn match treePart #`# - syn match treePartFile #[|`]-#hs=s+1 contains=treePart - - "quickhelp syntax elements - syn match treeHelpKey #" \{1,2\}[^ ]*:#hs=s+2,he=e-1 - syn match treeHelpKey #" \{1,2\}[^ ]*,#hs=s+2,he=e-1 - 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 treeHelpCommand #" :.\{-}\>#hs=s+3 - syn match treeHelp #^".*# contains=treeHelpKey,treeHelpTitle,treeFlag,treeToggleOff,treeToggleOn,treeHelpCommand - - "highlighting for readonly files - syn match treeRO #.*\[RO\]#hs=s+2 contains=treeFlag,treeBookmark,treePart,treePartFile - - "highlighting for sym links - syn match treeLink #[^-| `].* -> # contains=treeBookmark,treeOpenable,treeClosable,treeDirSlash - - "highlighing for directory nodes and file nodes - syn match treeDirSlash #/# - syn match treeDir #[^-| `].*/# contains=treeLink,treeDirSlash,treeOpenable,treeClosable - syn match treeExecFile #[|`]-.*\*\($\| \)# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark - syn match treeFile #|-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark,treeExecFile - syn match treeFile #`-.*# contains=treeLink,treePart,treeRO,treePartFile,treeBookmark,treeExecFile - 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 - hi def link treePart Special - hi def link treePartFile Type - hi def link treeFile Normal - hi def link treeExecFile Title - hi def link treeDirSlash Identifier - hi def link treeClosable Type +"FUNCTION: s:setCommonBufOptions() {{{2 +function! s:setCommonBufOptions() + "throwaway buffer options + setlocal noswapfile + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal nowrap + setlocal foldcolumn=0 + setlocal nobuflisted + setlocal nospell + if g:NERDTreeShowLineNumbers + setlocal nu else - hi def link treePart Normal - hi def link treePartFile Normal - hi def link treeFile Normal - hi def link treeClosable Title + setlocal nonu + if v:version >= 703 + setlocal nornu + endif endif - hi def link treeBookmarksHeader statement - hi def link treeBookmarksLeader ignore - hi def link treeBookmarkName Identifier - hi def link treeBookmark normal + iabc <buffer> - 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 + if g:NERDTreeHighlightCursorline + setlocal cursorline + endif - hi def link treeDir Directory - hi def link treeUp Directory - hi def link treeCWD Statement - hi def link treeLink Macro - hi def link treeOpenable Title - hi def link treeFlag ignore - hi def link treeRO WarningMsg - hi def link treeBookmark Statement + call s:setupStatusline() - hi def link NERDTreeCurrentNode Search + + let b:treeShowHelp = 0 + let b:NERDTreeIgnoreEnabled = 1 + let b:NERDTreeShowFiles = g:NERDTreeShowFiles + let b:NERDTreeShowHidden = g:NERDTreeShowHidden + let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks + setfiletype nerdtree + call s:bindMappings() endfunction +"FUNCTION: s:setupStatusline() {{{2 +function! s:setupStatusline() + if g:NERDTreeStatusline != -1 + let &l:statusline = g:NERDTreeStatusline + endif +endfunction "FUNCTION: s:stripMarkupFromLine(line, removeLeadingSpaces){{{2 "returns the given line with all the tree parts stripped off " @@ -3459,7 +3415,7 @@ function! s:stripMarkupFromLine(line, removeLeadingSpaces) let line = substitute (line, '*\ze\($\| \)', "","") let wasdir = 0 - if line =~ '/$' + if line =~# '/$' let wasdir = 1 endif let line = substitute (line,' -> .*',"","") " remove link to @@ -3579,7 +3535,7 @@ function! s:bindMappings() "bind all the user custom maps call s:KeyMap.BindAll() - command! -buffer -nargs=1 Bookmark :call <SID>bookmarkNode('<args>') + command! -buffer -nargs=? Bookmark :call <SID>bookmarkNode('<args>') command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 RevealBookmark :call <SID>revealBookmark('<args>') command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 OpenBookmark :call <SID>openBookmark('<args>') command! -buffer -complete=customlist,s:completeBookmarks -nargs=* ClearBookmarks call <SID>clearBookmarks('<args>') @@ -3591,11 +3547,15 @@ endfunction " FUNCTION: s:bookmarkNode(name) {{{2 " Associate the current node with the given name -function! s:bookmarkNode(name) +function! s:bookmarkNode(...) let currentNode = s:TreeFileNode.GetSelected() if currentNode != {} + let name = a:1 + if empty(name) + let name = currentNode.path.getLastPathComponent(0) + endif try - call currentNode.bookmark(a:name) + call currentNode.bookmark(name) call s:renderView() catch /^NERDTree.IllegalBookmarkNameError/ call s:echo("bookmark names must not contain spaces") @@ -3612,19 +3572,17 @@ function! s:checkForActivate() let currentNode = s:TreeFileNode.GetSelected() if currentNode != {} let startToCur = strpart(getline(line(".")), 0, col(".")) - let char = strpart(startToCur, strlen(startToCur)-1, 1) - "if they clicked a dir, check if they clicked on the + or ~ sign - "beside it if currentNode.path.isDirectory - if startToCur =~ s:tree_markup_reg . '$' && char =~ '[+~]' + if startToCur =~# s:tree_markup_reg . '$' && startToCur =~# '[+~▾▸]$' call s:activateNode(0) return endif endif if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3 - if char !~ s:tree_markup_reg && startToCur !~ '\/$' + let char = strpart(startToCur, strlen(startToCur)-1, 1) + if char !~# s:tree_markup_reg call s:activateNode(0) return endif @@ -4024,7 +3982,7 @@ endfunction "re-rendered function! s:upDir(keepState) let cwd = b:NERDTreeRoot.path.str({'format': 'UI'}) - if cwd ==# "/" || cwd =~ '^[^/]..$' + if cwd ==# "/" || cwd =~# '^[^/]..$' call s:echo("already at top dir") else if !a:keepState diff --git a/.vim/syntax/nerdtree.vim b/.vim/syntax/nerdtree.vim @@ -0,0 +1,88 @@ +let s:tree_up_dir_line = '.. (up a dir)' +"NERDTreeFlags are syntax items that should be invisible, but give clues as to +"how things should be highlighted +syn match NERDTreeFlag #\~# +syn match NERDTreeFlag #\[RO\]# + +"highlighting for the .. (up dir) line at the top of the tree +execute "syn match NERDTreeUp #\\V". s:tree_up_dir_line ."#" + +"highlighting for the ~/+ symbols for the directory nodes +syn match NERDTreeClosable #\~\<# +syn match NERDTreeClosable #\~\.# +syn match NERDTreeOpenable #+\<# +syn match NERDTreeOpenable #+\.#he=e-1 + +"highlighting for the tree structural parts +syn match NERDTreePart #|# +syn match NERDTreePart #`# +syn match NERDTreePartFile #[|`]-#hs=s+1 contains=NERDTreePart + +"quickhelp syntax elements +syn match NERDTreeHelpKey #" \{1,2\}[^ ]*:#hs=s+2,he=e-1 +syn match NERDTreeHelpKey #" \{1,2\}[^ ]*,#hs=s+2,he=e-1 +syn match NERDTreeHelpTitle #" .*\~#hs=s+2,he=e-1 contains=NERDTreeFlag +syn match NERDTreeToggleOn #".*(on)#hs=e-2,he=e-1 contains=NERDTreeHelpKey +syn match NERDTreeToggleOff #".*(off)#hs=e-3,he=e-1 contains=NERDTreeHelpKey +syn match NERDTreeHelpCommand #" :.\{-}\>#hs=s+3 +syn match NERDTreeHelp #^".*# contains=NERDTreeHelpKey,NERDTreeHelpTitle,NERDTreeFlag,NERDTreeToggleOff,NERDTreeToggleOn,NERDTreeHelpCommand + +"highlighting for readonly files +syn match NERDTreeRO #.*\[RO\]#hs=s+2 contains=NERDTreeFlag,NERDTreeBookmark,NERDTreePart,NERDTreePartFile + +"highlighting for sym links +syn match NERDTreeLink #[^-| `].* -> # contains=NERDTreeBookmark,NERDTreeOpenable,NERDTreeClosable,NERDTreeDirSlash + +"highlighing for directory nodes and file nodes +syn match NERDTreeDirSlash #/# +syn match NERDTreeDir #[^-| `].*/# contains=NERDTreeLink,NERDTreeDirSlash,NERDTreeOpenable,NERDTreeClosable +syn match NERDTreeExecFile #[|` ].*\*\($\| \)# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark +syn match NERDTreeFile #|-.*# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark,NERDTreeExecFile +syn match NERDTreeFile #`-.*# contains=NERDTreeLink,NERDTreePart,NERDTreeRO,NERDTreePartFile,NERDTreeBookmark,NERDTreeExecFile +syn match NERDTreeCWD #^[</].*$# + +"highlighting for bookmarks +syn match NERDTreeBookmark # {.*}#hs=s+1 + +"highlighting for the bookmarks table +syn match NERDTreeBookmarksLeader #^># +syn match NERDTreeBookmarksHeader #^>-\+Bookmarks-\+$# contains=NERDTreeBookmarksLeader +syn match NERDTreeBookmarkName #^>.\{-} #he=e-1 contains=NERDTreeBookmarksLeader +syn match NERDTreeBookmark #^>.*$# contains=NERDTreeBookmarksLeader,NERDTreeBookmarkName,NERDTreeBookmarksHeader + +if exists("g:NERDChristmasTree") && g:NERDChristmasTree + hi def link NERDTreePart Special + hi def link NERDTreePartFile Type + hi def link NERDTreeFile Normal + hi def link NERDTreeExecFile Title + hi def link NERDTreeDirSlash Identifier + hi def link NERDTreeClosable Type +else + hi def link NERDTreePart Normal + hi def link NERDTreePartFile Normal + hi def link NERDTreeFile Normal + hi def link NERDTreeClosable Title +endif + +hi def link NERDTreeBookmarksHeader statement +hi def link NERDTreeBookmarksLeader ignore +hi def link NERDTreeBookmarkName Identifier +hi def link NERDTreeBookmark normal + +hi def link NERDTreeHelp String +hi def link NERDTreeHelpKey Identifier +hi def link NERDTreeHelpCommand Identifier +hi def link NERDTreeHelpTitle Macro +hi def link NERDTreeToggleOn Question +hi def link NERDTreeToggleOff WarningMsg + +hi def link NERDTreeDir Directory +hi def link NERDTreeUp Directory +hi def link NERDTreeCWD Statement +hi def link NERDTreeLink Macro +hi def link NERDTreeOpenable Title +hi def link NERDTreeFlag ignore +hi def link NERDTreeRO WarningMsg +hi def link NERDTreeBookmark Statement + +hi def link NERDTreeCurrentNode Search