Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show file lines #1384

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions lib/nerdtree/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions lib/nerdtree/ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions plugin/NERD_tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand All @@ -144,6 +146,7 @@ call nerdtree#loadClassFiles()
"============================================================
call nerdtree#ui_glue#setupCommands()


" SECTION: Auto commands {{{1
"============================================================
augroup NERDTree
Expand Down