Skip to content

Lines in file are displayed in NERDTree. #1328

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->
#### 6.10
- **.17**: Lines in file are displayed in explorer. (hsnks100) [#1328](https://github.com/preservim/nerdtree/pull/1328)
- **.16**: Fix documentation errors. (lifecrisis) [#1269](https://github.com/preservim/nerdtree/pull/1269)
- **.15**: Ensure backward compatible testing of types. (lifecrisis) [#1266](https://github.com/preservim/nerdtree/pull/1266)
- **.14**: Replace trim() with a version-compatible alternative. (PhilRunninger) [#1265](https://github.com/preservim/nerdtree/pull/1265)
Expand Down
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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
17 changes: 17 additions & 0 deletions lib/nerdtree/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ function! s:Path.cacheDisplayString() abort
let self.cachedDisplayString = self.addDelimiter(self.cachedDisplayString) . ' -> ' . self.symLinkDest
endif

if !self.isDirectory && g:NERDTreeFileLines != 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]
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
2 changes: 2 additions & 0 deletions plugin/NERD_tree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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()
let g:NERDTreeDirArrowExpandable = get(g:, 'NERDTreeDirArrowExpandable', '▸')
Expand Down Expand Up @@ -142,6 +143,7 @@ call nerdtree#loadClassFiles()
"============================================================
call nerdtree#ui_glue#setupCommands()


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