Skip to content

Commit

Permalink
Add a NERDTreeToggleVCS command to the vcs plugin (#1060)
Browse files Browse the repository at this point in the history
* NERDTreeToggleVCS

* nerdtree toggle vcs documentation

* fix function documentation

* changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

* simplify toggletreevcs

* Update CHANGELOG.md
  • Loading branch information
willfindlay authored and PhilRunninger committed Nov 22, 2019
1 parent 8d9b8da commit 82b1649
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
in an unordered list. The format is:
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->

#### 6.3
- **.0**: Add new command that behaves like NERDTreeToggle but defaults to the root of a VCS repository. (willfindlay) [#1060](https://github.com/scrooloose/nerdtree/pull/1060)
#### 6.2
- **.1**: Menu option, 'copy path to clipboard' is aware of VIM clipboard option (jhzn) [#1056](https://github.com/scrooloose/nerdtree/pull/1056)
- **.0**: Support tab-specific CWDs (PhilRunninger) [#1032](https://github.com/scrooloose/nerdtree/pull/1032)
Expand Down
8 changes: 8 additions & 0 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ The following features and functionality are provided by the NERDTree:
again. If no NERDTree exists for this tab then this command acts the
same as the |:NERDTree| command.

:NERDTreeToggleVCS [<start-directory> | <bookmark>] *:NERDTreeToggleVCS*
Like |:NERDTreeToggle|, but searches up the directory tree to find the top of
the version control system repository, and roots the NERDTree there. It
works with Git, Subversion, Mercurial, Bazaar, and Darcs repositories. A
couple of examples: >
:NERDTreeToggleVCS /home/marty/nerdtree/doc (opens /home/marty/nerdtree)
:NERDTreeToggleVCS (opens root of repository containing CWD)
:NERDTreeFocus *:NERDTreeFocus*
Opens (or reopens) the NERDTree if it is not currently visible;
otherwise, the cursor is moved to the already-open NERDTree.
Expand Down
9 changes: 9 additions & 0 deletions nerdtree_plugin/vcs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"
" ============================================================================
command! -n=? -complete=dir -bar NERDTreeVCS :call <SID>CreateTabTreeVCS('<args>')
command! -n=? -complete=dir -bar NERDTreeToggleVCS :call <SID>ToggleTabTreeVCS('<args>')

" FUNCTION: s:CreateTabTreeVCS(a:name) {{{1
function! s:CreateTabTreeVCS(name)
Expand All @@ -19,6 +20,14 @@ function! s:CreateTabTreeVCS(name)
call g:NERDTreeCreator.createTabTree(empty(l:path) ? "" : l:path._str())
endfunction

" FUNCTION: s:ToggleTabTreeVCS(a:name) {{{1
" Behaves the same as ToggleTabTree except roots directory at VCS root
function! s:ToggleTabTreeVCS(name)
let l:path = g:NERDTreeCreator._pathForString(a:name)
let l:path = s:FindParentVCSRoot(l:path)
call g:NERDTreeCreator.toggleTabTree(empty(l:path) ? "" : l:path._str())
endfunction

" FUNCTION: s:FindParentVCSRoot(a:path) {{{1
" Finds the root version control system folder of the given path. If a:path is
" not part of a repository, return the original path.
Expand Down

0 comments on commit 82b1649

Please sign in to comment.