mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 03:43:50 -05:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
690d061b59 | ||
|
|
0b3c1dc0fa | ||
|
|
915f64b3be | ||
|
|
b4b4130f3c | ||
|
|
9b465acb27 | ||
|
|
09aec2cfca | ||
|
|
fbb71fcd90 | ||
|
|
6ad85ec29b | ||
|
|
f3a4d8eaa8 | ||
|
|
bdf81a086d | ||
|
|
60b5e602e9 |
@@ -13,6 +13,13 @@
|
||||
- Pull Request Title n (PR Author) [PR Number](Link to PR)
|
||||
-->
|
||||
#### 7.1
|
||||
- **.3**:
|
||||
- docs: update FAQ snippets containing quit command. (rzvxa) [#1417](https://github.com/preservim/nerdtree/pull/1417)
|
||||
- feat: jump to bookmark table shortcut. (ds2606, rzvxa) [#1394](https://github.com/preservim/nerdtree/pull/1394)
|
||||
- fix: typo in docs for show file lines setting. (lothardp) [#1426](https://github.com/preservim/nerdtree/pull/1426)
|
||||
- **.2**:
|
||||
- fix: GetWinNum regex pattern. (rzvxa) [#1409](https://github.com/preservim/nerdtree/pull/1409)
|
||||
- fix: session restore for nerdtree buffers. (rzvxa) [#1405](https://github.com/preservim/nerdtree/pull/1405)
|
||||
- **.1**:
|
||||
- fix: change default binding of filelines to `FL`. (rzvxa) [#1400](https://github.com/preservim/nerdtree/pull/1400)
|
||||
- fix: toggle zoom resizing. (ds2606) [#1395](https://github.com/preservim/nerdtree/pull/1395)
|
||||
|
||||
@@ -87,7 +87,7 @@ After installing NERDTree, the best way to learn it is to turn on the Quick Help
|
||||
NERDTree can be extended with custom mappings and functions using its built-in API. The details of this API are described in the included documentation. Several plugins have been written, and are available on Github for installation like any other plugin. The plugins in this list are maintained (or not) by their respective owners, and certain combinations may be incompatible.
|
||||
|
||||
* [Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin): Shows Git status flags for files and folders in NERDTree.
|
||||
* [ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons): Adds filetype-specific icons to NERDTree files and folders,
|
||||
* [ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons): Adds filetype-specific icons to NERDTree files and folders.
|
||||
* [tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight): Adds syntax highlighting to NERDTree based on filetype.
|
||||
* [scrooloose/nerdtree-project-plugin](https://github.com/scrooloose/nerdtree-project-plugin): Saves and restores the state of the NERDTree between sessions.
|
||||
* [PhilRunninger/nerdtree-buffer-ops](https://github.com/PhilRunninger/nerdtree-buffer-ops): 1) Highlights open files in a different color. 2) Closes a buffer directly from NERDTree.
|
||||
@@ -150,6 +150,24 @@ autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in
|
||||
|
||||
### How can I close Vim or a tab automatically when NERDTree is the last window?
|
||||
|
||||
Because of the changes in how Vim handles its `autocmd` and layout locking `quit` command is no longer available in Vim9 auto commands, Depending on which version you're running select one of these solutions.
|
||||
|
||||
__NeoVim users should be able to choose either one of them!__
|
||||
|
||||
#### Vim9
|
||||
|
||||
```vim
|
||||
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
||||
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
|
||||
```
|
||||
---
|
||||
```vim
|
||||
" Close the tab if NERDTree is the only window remaining in it.
|
||||
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
|
||||
```
|
||||
|
||||
#### Vim8 or older
|
||||
|
||||
```vim
|
||||
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
||||
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
|
||||
|
||||
@@ -234,6 +234,38 @@ function! nerdtree#pathEquals(lhs, rhs) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: nerdtree#onBufLeave() {{{2
|
||||
" used for handling the nerdtree BufLeave/WinLeave events.
|
||||
function! nerdtree#onBufLeave() abort
|
||||
" detect whether we are in the middle of sourcing a session.
|
||||
" if it is a buffer from the sourced session we need to restore it.
|
||||
if exists('g:SessionLoad') && !exists('b:NERDTree')
|
||||
let bname = bufname('%')
|
||||
" is the buffer for a tab tree?
|
||||
if bname =~# '^' . g:NERDTreeCreator.BufNamePrefix() . 'tab_\d\+$'
|
||||
" rename loaded buffer and mark it as trash to prevent this event
|
||||
" getting fired again
|
||||
exec 'file TRASH_' . bname
|
||||
" delete the trash buffer
|
||||
exec 'bwipeout!'
|
||||
" rescue the tab tree at the current working directory
|
||||
call g:NERDTreeCreator.CreateTabTree(getcwd())
|
||||
" is the buffer for a window tree?
|
||||
elseif bname =~# '^' . g:NERDTreeCreator.BufNamePrefix(). 'win_\d\+$'
|
||||
" rescue the window tree at the current working directory
|
||||
call g:NERDTreeCreator.CreateWindowTree(getcwd())
|
||||
else " unknown buffer type
|
||||
" rename buffer to mark it as broken.
|
||||
exec 'file BROKEN_' . bname
|
||||
call nerdtree#echoError('Failed to restore "' . bname . '" from session. Is this session created with an older version of NERDTree?')
|
||||
endif
|
||||
else
|
||||
if g:NERDTree.IsOpen()
|
||||
call b:NERDTree.ui.saveScreenState()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" SECTION: View Functions {{{1
|
||||
"============================================================
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ function! nerdtree#ui_glue#createDefaultBindings() abort
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpRoot, 'scope': 'all', 'callback': s.'jumpToRoot' })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': 'Node', 'callback': s.'jumpToNextSibling' })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': 'Node', 'callback': s.'jumpToPrevSibling' })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpBookmarks, 'scope': 'all', 'callback': s.'jumpToBookmarks' })
|
||||
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': 'Node', 'callback': s . 'openInNewTab' })
|
||||
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': 'Node', 'callback': s . 'openInNewTabSilent' })
|
||||
@@ -496,6 +497,21 @@ function! s:jumpToSibling(node, forward) abort
|
||||
call b:NERDTree.ui.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:jumpToBookmarks() {{{1
|
||||
" moves the cursor to the bookmark table
|
||||
function! s:jumpToBookmarks() abort
|
||||
try
|
||||
if b:NERDTree.ui.getShowBookmarks()
|
||||
call g:NERDTree.CursorToBookmarkTable()
|
||||
else
|
||||
call b:NERDTree.ui.setShowBookmarks(1)
|
||||
endif
|
||||
catch /^NERDTree/
|
||||
call nerdtree#echoError('Failed to jump to the bookmark table')
|
||||
return
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1
|
||||
" Open the Bookmark that has the specified name. This function provides the
|
||||
" implementation for the :OpenBookmark command.
|
||||
|
||||
@@ -1073,7 +1073,7 @@ mapping and is useful for drastically shrinking the tree when you are
|
||||
navigating to a different part of the tree.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*NERDTreeShowFilesLines*
|
||||
*NERDTreeFileLines*
|
||||
Values: 0 or 1.
|
||||
Default: 0.
|
||||
|
||||
@@ -1083,8 +1083,8 @@ file.
|
||||
This setting can be toggled dynamically, per tree, with the |NERDTree-FL|
|
||||
mapping.
|
||||
Use one of the follow lines for this setting: >
|
||||
let NERDTreeShowFilesLines=0
|
||||
let NERDTreeShowFilesLines=1
|
||||
let NERDTreeFileLines=0
|
||||
let NERDTreeFileLines=1
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
*NERDTreeShowHidden*
|
||||
|
||||
@@ -118,7 +118,7 @@ function! s:Creator.createWindowTree(dir)
|
||||
|
||||
"we need a unique name for each window tree buffer to ensure they are
|
||||
"all independent
|
||||
exec g:NERDTreeCreatePrefix . ' edit ' . self._nextBufferName()
|
||||
exec g:NERDTreeCreatePrefix . ' edit ' . self._nextBufferName('win')
|
||||
|
||||
call self._createNERDTree(path, 'window')
|
||||
let b:NERDTree._previousBuf = bufnr(previousBuf)
|
||||
@@ -210,7 +210,7 @@ function! s:Creator._createTreeWin()
|
||||
let l:splitSize = g:NERDTreeWinSize
|
||||
|
||||
if !g:NERDTree.ExistsForTab()
|
||||
let t:NERDTreeBufName = self._nextBufferName()
|
||||
let t:NERDTreeBufName = self._nextBufferName('tab')
|
||||
silent! execute l:splitLocation . l:splitDirection . ' ' . l:splitSize . ' new'
|
||||
silent! execute 'edit ' . t:NERDTreeBufName
|
||||
silent! execute l:splitDirection . ' resize '. l:splitSize
|
||||
@@ -244,10 +244,22 @@ function! s:Creator.New()
|
||||
return newCreator
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:Creator._nextBufferName() {{{1
|
||||
" returns the buffer name for the next nerd tree
|
||||
function! s:Creator._nextBufferName()
|
||||
let name = s:Creator.BufNamePrefix() . self._nextBufferNumber()
|
||||
" FUNCTION: s:Creator._nextBufferName(type='') {{{1
|
||||
" gets an optional buffer type of either 'tab' or 'win'.
|
||||
" returns the buffer name for the next nerd tree of such type.
|
||||
function! s:Creator._nextBufferName(...)
|
||||
if a:0 > 0
|
||||
let type = a:1
|
||||
else
|
||||
let type = ''
|
||||
end
|
||||
let name = s:Creator.BufNamePrefix()
|
||||
if type ==# 'tab'
|
||||
let name = name . 'tab_'
|
||||
elseif type ==# 'win'
|
||||
let name = name . 'win_'
|
||||
endif
|
||||
let name = name . self._nextBufferNumber()
|
||||
return name
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ function! s:NERDTree.GetWinNum()
|
||||
|
||||
" If WindowTree, there is no t:NERDTreeBufName variable. Search all windows.
|
||||
for w in range(1,winnr('$'))
|
||||
if bufname(winbufnr(w)) =~# '^' . g:NERDTreeCreator.BufNamePrefix() . '\d\+$'
|
||||
if bufname(winbufnr(w)) =~# '^' . g:NERDTreeCreator.BufNamePrefix() . 'win_\d\+$'
|
||||
return w
|
||||
endif
|
||||
endfor
|
||||
|
||||
@@ -362,9 +362,10 @@ endfunction
|
||||
" returns the index of the pattern in g:NERDTreeSortOrder that this path matches
|
||||
function! s:Path.getSortOrderIndex()
|
||||
let i = 0
|
||||
let l:lpc = self.getLastPathComponent(1)
|
||||
while i < len(g:NERDTreeSortOrder)
|
||||
if g:NERDTreeSortOrder[i] !~? '\[\[-\?\(timestamp\|size\|extension\)\]\]' &&
|
||||
\ self.getLastPathComponent(1) =~# g:NERDTreeSortOrder[i]
|
||||
\ l:lpc =~# g:NERDTreeSortOrder[i]
|
||||
return i
|
||||
endif
|
||||
let i = i + 1
|
||||
|
||||
@@ -591,6 +591,7 @@ function! s:TreeDirNode.refresh()
|
||||
let newNode = g:NERDTreeFileNode.New(path, self.getNerdtree())
|
||||
let newNode.parent = self
|
||||
call add(newChildNodes, newNode)
|
||||
call g:NERDTreePathNotifier.NotifyListeners('init', newNode.path, newNode.getNerdtree(), {})
|
||||
endif
|
||||
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
|
||||
let invalidFilesFound += 1
|
||||
@@ -715,6 +716,7 @@ function! s:TreeDirNode.transplantChild(newNode)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
call self.refresh()
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
||||
|
||||
@@ -62,6 +62,7 @@ function! s:UI._dumpHelp()
|
||||
let help .= "\"\n\" ----------------------------\n"
|
||||
let help .= "\" Bookmark table mappings~\n"
|
||||
let help .= "\" double-click,\n"
|
||||
let help .= '" '. g:NERDTreeMapJumpBookmarks .": jump to bookmark table\n"
|
||||
let help .= '" '. g:NERDTreeMapActivateNode .": open bookmark\n"
|
||||
let help .= '" '. g:NERDTreeMapPreview .": preview file\n"
|
||||
let help .= '" '. g:NERDTreeMapPreview .": find dir in tree\n"
|
||||
@@ -482,10 +483,10 @@ function! s:UI.toggleIgnoreFilter()
|
||||
call self.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
|
||||
" Toggle the visibility of the Bookmark table.
|
||||
function! s:UI.toggleShowBookmarks()
|
||||
let self._showBookmarks = !self._showBookmarks
|
||||
" FUNCTION: s:UI.setShowBookmarks() {{{1
|
||||
" Sets the visibility of the Bookmark table.
|
||||
function! s:UI.setShowBookmarks(value)
|
||||
let self._showBookmarks = a:value
|
||||
|
||||
if self.getShowBookmarks()
|
||||
call self.nerdtree.render()
|
||||
@@ -503,6 +504,12 @@ function! s:UI.toggleShowBookmarks()
|
||||
call self.centerView()
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
|
||||
" Toggle the visibility of the Bookmark table.
|
||||
function! s:UI.toggleShowBookmarks()
|
||||
call self.setShowBookmarks(!self._showBookmarks)
|
||||
endfunction
|
||||
|
||||
" FUNCTION: s:UI.toggleShowFiles() {{{1
|
||||
" toggles the display of hidden files
|
||||
function! s:UI.toggleShowFiles()
|
||||
|
||||
@@ -211,6 +211,7 @@ function! NERDTreeAddNode()
|
||||
call b:NERDTree.render()
|
||||
elseif parentNode.isOpen || !empty(parentNode.children)
|
||||
call parentNode.addChild(newTreeNode, 1)
|
||||
call g:NERDTreePathNotifier.NotifyListeners('init', newTreeNode.path, newTreeNode.getNerdtree(), {})
|
||||
call NERDTreeRender()
|
||||
call newTreeNode.putCursorHere(1, 0)
|
||||
endif
|
||||
|
||||
@@ -101,6 +101,7 @@ endif
|
||||
|
||||
"SECTION: Init variable calls for key mappings {{{2
|
||||
let g:NERDTreeMapCustomOpen = get(g:, 'NERDTreeMapCustomOpen', '<CR>')
|
||||
let g:NERDTreeMapJumpBookmarks = get(g:, 'NERDTreeMapJumpBookmarks', 'gb')
|
||||
let g:NERDTreeMapActivateNode = get(g:, 'NERDTreeMapActivateNode', 'o')
|
||||
let g:NERDTreeMapChangeRoot = get(g:, 'NERDTreeMapChangeRoot', 'C')
|
||||
let g:NERDTreeMapChdir = get(g:, 'NERDTreeMapChdir', 'cd')
|
||||
@@ -151,7 +152,7 @@ call nerdtree#ui_glue#setupCommands()
|
||||
"============================================================
|
||||
augroup NERDTree
|
||||
"Save the cursor position whenever we close the nerd tree
|
||||
exec 'autocmd BufLeave,WinLeave '. g:NERDTreeCreator.BufNamePrefix() .'* if g:NERDTree.IsOpen() | call b:NERDTree.ui.saveScreenState() | endif'
|
||||
exec 'autocmd BufLeave,WinLeave '. g:NERDTreeCreator.BufNamePrefix() .'* call nerdtree#onBufLeave()'
|
||||
|
||||
"disallow insert mode in the NERDTree
|
||||
exec 'autocmd BufEnter,WinEnter '. g:NERDTreeCreator.BufNamePrefix() .'* stopinsert'
|
||||
|
||||
Reference in New Issue
Block a user