Skip to content

Commit

Permalink
Enable opening bookmarks in split windows. (#1144)
Browse files Browse the repository at this point in the history
* Add open/preview in split/vsplit to bookmarks.

* Make preview split/vsplit bookmark work only on file nodes.

* Add quickhelp text for split/vsplit commands on bookmarks.

* Handle previewing directory bookmarks properly.

* Update documentation: bookmarks can be opened in a split/vsplit.

* Update version number in change log.
  • Loading branch information
PhilRunninger authored Jun 23, 2020
1 parent d48ab70 commit 6571452
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
version in an unordered list. The format is:
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
-->
#### 6.9
- **.0**: Enable opening bookmarks in split windows. (PhilRunninger) [#1144](https://github.com/preservim/nerdtree/pull/1144)
#### 6.8
- **.0**: Allow concealed characters to show another character. (PhilRunninger) [#1138](https://github.com/preservim/nerdtree/pull/1138)
#### 6.7
Expand Down
28 changes: 27 additions & 1 deletion autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ function! nerdtree#ui_glue#createDefaultBindings() abort
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': 'all', 'callback': s.'activateAll' })

call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': 'Node', 'callback': s.'openHSplit' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenSplit, 'scope': 'Bookmark', 'callback': s.'openHSplitBookmark' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': 'Node', 'callback': s.'openVSplit' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenVSplit, 'scope': 'Bookmark', 'callback': s.'openVSplitBookmark' })

call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreview, 'scope': 'Node', 'callback': s.'previewNodeCurrent' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': 'Node', 'callback': s.'previewNodeVSplit' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': 'Node', 'callback': s.'previewNodeHSplit' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewSplit, 'scope': 'Bookmark', 'callback': s.'previewNodeHSplitBookmark' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': 'Node', 'callback': s.'previewNodeVSplit' })
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapPreviewVSplit, 'scope': 'Bookmark', 'callback': s.'previewNodeVSplitBookmark' })

call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenRecursively, 'scope': 'DirNode', 'callback': s.'openNodeRecursively' })

Expand Down Expand Up @@ -511,6 +515,28 @@ function! s:openVSplit(target) abort
call a:target.activate({'where': 'v'})
endfunction

"FUNCTION: s:openHSplitBookmark(bookmark) {{{1
"handle the user activating a bookmark
function! s:openHSplitBookmark(bm) abort
call a:bm.activate(b:NERDTree, !a:bm.path.isDirectory ? {'where': 'h'} : {})
endfunction

"FUNCTION: s:openVSplitBookmark(bookmark) {{{1
"handle the user activating a bookmark
function! s:openVSplitBookmark(bm) abort
call a:bm.activate(b:NERDTree, !a:bm.path.isDirectory ? {'where': 'v'} : {})
endfunction

" FUNCTION: s:previewHSplitBookmark(bookmark) {{{1
function! s:previewNodeHSplitBookmark(bookmark) abort
call a:bookmark.activate(b:NERDTree, !a:bookmark.path.isDirectory ? {'stay': 1, 'where': 'h', 'keepopen': 1} : {})
endfunction

" FUNCTION: s:previewVSplitBookmark(bookmark) {{{1
function! s:previewNodeVSplitBookmark(bookmark) abort
call a:bookmark.activate(b:NERDTree, !a:bookmark.path.isDirectory ? {'stay': 1, 'where': 'v', 'keepopen': 1} : {})
endfunction

" FUNCTION: s:openExplorer(node) {{{1
function! s:openExplorer(node) abort
call a:node.openExplorer()
Expand Down
4 changes: 2 additions & 2 deletions doc/NERDTree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ The same as |NERDTree-t| except that the focus is kept in the current tab.
*NERDTree-i*
Default key: i
Map setting: *NERDTreeMapOpenSplit*
Applies to: files.
Applies to: files, and bookmarks pointing to files.

Opens the selected file in a new split window and puts the cursor in the new
window.
Expand All @@ -370,7 +370,7 @@ The default key combo for this mapping is "g" + NERDTreeMapOpenSplit (see
*NERDTree-s*
Default key: s
Map setting: *NERDTreeMapOpenVSplit*
Applies to: files.
Applies to: files, and bookmarks pointing to files.

Opens the selected file in a new vertically split window and puts the cursor
in the new window.
Expand Down
4 changes: 4 additions & 0 deletions lib/nerdtree/ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function! s:UI._dumpHelp()
let help .= '" '. g:NERDTreeMapPreview .": find dir in tree\n"
let help .= '" '. g:NERDTreeMapOpenInTab.": open in new tab\n"
let help .= '" '. g:NERDTreeMapOpenInTabSilent .": open in new tab silently\n"
let help .= '" '. g:NERDTreeMapOpenSplit .": open split\n"
let help .= '" '. g:NERDTreeMapPreviewSplit .": preview split\n"
let help .= '" '. g:NERDTreeMapOpenVSplit .": open vsplit\n"
let help .= '" '. g:NERDTreeMapPreviewVSplit .": preview vsplit\n"
let help .= '" '. g:NERDTreeMapCustomOpen .": custom open\n"
let help .= '" '. g:NERDTreeMapDeleteBookmark .": delete bookmark\n"

Expand Down

0 comments on commit 6571452

Please sign in to comment.