diff --git a/README.markdown b/README.markdown index 6312960f..210ec312 100644 --- a/README.markdown +++ b/README.markdown @@ -188,6 +188,28 @@ let g:NERDTreeDirArrowCollapsible = '?' ``` The preceding values are the non-Windows default arrow symbols. Setting these variables to empty strings will remove the arrows completely and shift the entire tree two character positions to the left. See `:h NERDTreeDirArrowExpandable` for more details. +### How can I show lines of files? + +```vim +let g:NERDTreeFileLines = 1 +``` + +Lines in the file are displayed as shown below. +``` + + let NERDTreeShowFilesLines=0 + let NERDTreeShowFilesLines=1 +< ------------------------------------------------------------------------------ *NERDTreeShowHidden* Values: 0 or 1. diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 2165c57a..4d97a6f4 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -65,6 +65,25 @@ function! s:Path.cacheDisplayString() abort let self.cachedDisplayString = self.addDelimiter(self.cachedDisplayString) . ' -> ' . self.symLinkDest endif + if !self.isDirectory && b:NERDTree.ui.getShowFileLines() != 0 + let l:bufname = self.str({'format': 'Edit'}) + let l:lines = 0 + if executable('wc') + let l:lines = split(system('wc -l "'.l:bufname.'"'))[0] + elseif nerdtree#runningWindows() + let l:lines = substitute(system('type "'.l:bufname.'" | find /c /v ""'), '\n', '', 'g') + else + let s:lines = readfile(l:bufname) + let l:lines = 0 + for s:line in s:lines + let l:lines += 1 + if l:lines >= 20000 + break + endif + endfor + endif + let self.cachedDisplayString = self.addDelimiter(self.cachedDisplayString) . ' ('.l:lines.')' + endif if self.isReadOnly let self.cachedDisplayString = self.addDelimiter(self.cachedDisplayString) . ' ['.g:NERDTreeGlyphReadOnly.']' endif diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim index a481ba47..358a948b 100644 --- a/lib/nerdtree/ui.vim +++ b/lib/nerdtree/ui.vim @@ -103,6 +103,7 @@ function! s:UI._dumpHelp() let help .= '" '. g:NERDTreeMapToggleFilters .': file filters (' . (self.isIgnoreFilterEnabled() ? 'on' : 'off') . ")\n" let help .= '" '. g:NERDTreeMapToggleFiles .': files (' . (self.getShowFiles() ? 'on' : 'off') . ")\n" let help .= '" '. g:NERDTreeMapToggleBookmarks .': bookmarks (' . (self.getShowBookmarks() ? 'on' : 'off') . ")\n" + let help .= '" '. g:NERDTreeMapToggleFileLines .': files lines (' . (self.getShowFileLines() ? 'on' : 'off') . ")\n" " add quickhelp entries for each custom key map let help .= "\"\n\" ----------------------------\n" @@ -147,6 +148,7 @@ function! s:UI.New(nerdtree) let newObj._showFiles = g:NERDTreeShowFiles let newObj._showHidden = g:NERDTreeShowHidden let newObj._showBookmarks = g:NERDTreeShowBookmarks + let newObj._showFileLines = g:NERDTreeFileLines return newObj endfunction @@ -284,6 +286,11 @@ function! s:UI.getShowHidden() return self._showHidden endfunction +" FUNCTION: s:UI.getShowFileLines() {{{1 +function! s:UI.getShowFileLines() + return self._showFileLines +endfunction + " FUNCTION: s:UI._indentLevelFor(line) {{{1 function! s:UI._indentLevelFor(line) " Replace multi-character DirArrows with a single space so the @@ -512,6 +519,15 @@ function! s:UI.toggleShowHidden() call self.centerView() endfunction +" FUNCTION: s:UI.toggleShowFileLines() {{{1 +" toggles the display of file lines +function! s:UI.toggleShowFileLines() + let self._showFileLines = !self._showFileLines + call self.nerdtree.root.refresh() + call self.renderViewSavingPosition() + call self.centerView() +endfunction + " FUNCTION: s:UI.toggleZoom() {{{1 " zoom (maximize/minimize) the NERDTree window function! s:UI.toggleZoom() diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index c26842a0..a4276701 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -53,6 +53,7 @@ let g:NERDTreeShowFiles = get(g:, 'NERDTreeShowFiles', 1 let g:NERDTreeShowHidden = get(g:, 'NERDTreeShowHidden', 0) let g:NERDTreeShowLineNumbers = get(g:, 'NERDTreeShowLineNumbers', 0) let g:NERDTreeSortDirs = get(g:, 'NERDTreeSortDirs', 1) +let g:NERDTreeFileLines = get(g:, 'NERDTreeFileLines', 0) if !nerdtree#runningWindows() && !nerdtree#runningCygwin() @@ -130,6 +131,7 @@ let g:NERDTreeMapToggleBookmarks = get(g:, 'NERDTreeMapToggleBookmarks', 'B') let g:NERDTreeMapToggleFiles = get(g:, 'NERDTreeMapToggleFiles', 'F') let g:NERDTreeMapToggleFilters = get(g:, 'NERDTreeMapToggleFilters', 'f') let g:NERDTreeMapToggleHidden = get(g:, 'NERDTreeMapToggleHidden', 'I') +let g:NERDTreeMapToggleFileLines = get(g:, 'NERDTreeMapToggleFileLines', 'L') let g:NERDTreeMapToggleZoom = get(g:, 'NERDTreeMapToggleZoom', 'A') let g:NERDTreeMapUpdir = get(g:, 'NERDTreeMapUpdir', 'u') let g:NERDTreeMapUpdirKeepOpen = get(g:, 'NERDTreeMapUpdirKeepOpen', 'U') @@ -144,6 +146,7 @@ call nerdtree#loadClassFiles() "============================================================ call nerdtree#ui_glue#setupCommands() + " SECTION: Auto commands {{{1 "============================================================ augroup NERDTree