Show file lines (#1384)

* Added showing lines of files in NERDTRee.

* Added dynamic binding and documentation

---------

Co-authored-by: Diallo Han <diallo@hpcnt.com>
This commit is contained in:
Ali Rezvani 2023-11-15 15:32:17 +03:30 committed by GitHub
parent 4c588f1820
commit 0cb04e9245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 0 deletions

View File

@ -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.
```
</pack/packer/start/nerdtree/
▸ autoload/
▸ doc/
▸ lib/
▸ nerdtree_plugin/
▸ plugin/
▸ syntax/
_config.yml (1)
CHANGELOG.md (307)
LICENCE (13)
README.markdown (234)
screenshot.png (219)
```
### Can NERDTree access remote files via scp or ftp?
Short answer: No, and there are no plans to add that functionality. However, Vim ships with a plugin that does just that. It's called netrw, and by adding the following lines to your `.vimrc`, you can use it to open files over the `scp:`, `ftp:`, or other protocols, while still using NERDTree for all local files. The function seamlessly makes the decision to open NERDTree or netrw, and other supported protocols can be added to the regular expression.

View File

@ -57,6 +57,7 @@ function! nerdtree#ui_glue#createDefaultBindings() abort
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFilters, 'scope': 'all', 'callback': s.'toggleIgnoreFilter' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFiles, 'scope': 'all', 'callback': s.'toggleShowFiles' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleBookmarks, 'scope': 'all', 'callback': s.'toggleShowBookmarks' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapToggleFileLines, 'scope': 'all', 'callback': s.'toggleShowFileLines' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseDir, 'scope': 'Node', 'callback': s.'closeCurrentDir' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapCloseChildren, 'scope': 'DirNode', 'callback': s.'closeChildren' })
@ -685,6 +686,12 @@ function! s:toggleShowHidden() abort
call b:NERDTree.ui.toggleShowHidden()
endfunction
" FUNCTION: s:toggleShowFileLines() {{{1
" toggles the display of hidden files
function! s:toggleShowFileLines() abort
call b:NERDTree.ui.toggleShowFileLines()
endfunction
" FUNCTION: s:toggleZoom() {{{1
function! s:toggleZoom() abort
call b:NERDTree.ui.toggleZoom()

View File

@ -287,6 +287,7 @@ I........Toggle whether hidden files displayed......................|NERDTree-I|
f........Toggle whether the file filters are used...................|NERDTree-f|
F........Toggle whether files are displayed.........................|NERDTree-F|
B........Toggle whether the bookmark table is displayed.............|NERDTree-B|
L........Toggle whether the bookmark table is displayed.............|NERDTree-L|
q........Close the NERDTree window..................................|NERDTree-q|
A........Zoom (maximize/minimize) the NERDTree window...............|NERDTree-A|
@ -601,6 +602,14 @@ Applies to: no restrictions.
Toggles whether the bookmarks table is displayed.
------------------------------------------------------------------------------
*NERDTree-L*
Default key: L
Map setting: *NERDTreeMapToggleFileLiness*
Applies to: no restrictions.
Toggles whether the number of lines in files is displayed.
------------------------------------------------------------------------------
*NERDTree-q*
Default key: q
@ -1063,6 +1072,20 @@ This setting can be toggled dynamically, per tree, with the |NERDTree-F|
mapping and is useful for drastically shrinking the tree when you are
navigating to a different part of the tree.
------------------------------------------------------------------------------
*NERDTreeShowFilesLines*
Values: 0 or 1.
Default: 0.
If this setting is set to 1 then the NERDTree shows number of lines for each
file.
This setting can be toggled dynamically, per tree, with the |NERDTree-L|
mapping.
Use one of the follow lines for this setting: >
let NERDTreeShowFilesLines=0
let NERDTreeShowFilesLines=1
<
------------------------------------------------------------------------------
*NERDTreeShowHidden*
Values: 0 or 1.

View File

@ -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

View File

@ -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()

View File

@ -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