Skip to content

Commit 6ad85ec

Browse files
rzvxads2606
andauthored
feat: jump to bookmark table shortcut. (#1394)
Co-authored-by: Daniel Schreck <[email protected]>
1 parent f3a4d8e commit 6ad85ec

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

autoload/nerdtree/ui_glue.vim

+16
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function! nerdtree#ui_glue#createDefaultBindings() abort
7070
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpRoot, 'scope': 'all', 'callback': s.'jumpToRoot' })
7171
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpNextSibling, 'scope': 'Node', 'callback': s.'jumpToNextSibling' })
7272
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpPrevSibling, 'scope': 'Node', 'callback': s.'jumpToPrevSibling' })
73+
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapJumpBookmarks, 'scope': 'all', 'callback': s.'jumpToBookmarks' })
7374

7475
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTab, 'scope': 'Node', 'callback': s . 'openInNewTab' })
7576
call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapOpenInTabSilent, 'scope': 'Node', 'callback': s . 'openInNewTabSilent' })
@@ -496,6 +497,21 @@ function! s:jumpToSibling(node, forward) abort
496497
call b:NERDTree.ui.centerView()
497498
endfunction
498499

500+
" FUNCTION: s:jumpToBookmarks() {{{1
501+
" moves the cursor to the bookmark table
502+
function! s:jumpToBookmarks() abort
503+
try
504+
if b:NERDTree.ui.getShowBookmarks()
505+
call g:NERDTree.CursorToBookmarkTable()
506+
else
507+
call b:NERDTree.ui.setShowBookmarks(1)
508+
endif
509+
catch /^NERDTree/
510+
call nerdtree#echoError('Failed to jump to the bookmark table')
511+
return
512+
endtry
513+
endfunction
514+
499515
" FUNCTION: nerdtree#ui_glue#openBookmark(name) {{{1
500516
" Open the Bookmark that has the specified name. This function provides the
501517
" implementation for the :OpenBookmark command.

lib/nerdtree/ui.vim

+11-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function! s:UI._dumpHelp()
6262
let help .= "\"\n\" ----------------------------\n"
6363
let help .= "\" Bookmark table mappings~\n"
6464
let help .= "\" double-click,\n"
65+
let help .= '" '. g:NERDTreeMapJumpBookmarks .": jump to bookmark table\n"
6566
let help .= '" '. g:NERDTreeMapActivateNode .": open bookmark\n"
6667
let help .= '" '. g:NERDTreeMapPreview .": preview file\n"
6768
let help .= '" '. g:NERDTreeMapPreview .": find dir in tree\n"
@@ -482,10 +483,10 @@ function! s:UI.toggleIgnoreFilter()
482483
call self.centerView()
483484
endfunction
484485

485-
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
486-
" Toggle the visibility of the Bookmark table.
487-
function! s:UI.toggleShowBookmarks()
488-
let self._showBookmarks = !self._showBookmarks
486+
" FUNCTION: s:UI.setShowBookmarks() {{{1
487+
" Sets the visibility of the Bookmark table.
488+
function! s:UI.setShowBookmarks(value)
489+
let self._showBookmarks = a:value
489490

490491
if self.getShowBookmarks()
491492
call self.nerdtree.render()
@@ -503,6 +504,12 @@ function! s:UI.toggleShowBookmarks()
503504
call self.centerView()
504505
endfunction
505506

507+
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
508+
" Toggle the visibility of the Bookmark table.
509+
function! s:UI.toggleShowBookmarks()
510+
call self.setShowBookmarks(!self._showBookmarks)
511+
endfunction
512+
506513
" FUNCTION: s:UI.toggleShowFiles() {{{1
507514
" toggles the display of hidden files
508515
function! s:UI.toggleShowFiles()

plugin/NERD_tree.vim

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ endif
101101

102102
"SECTION: Init variable calls for key mappings {{{2
103103
let g:NERDTreeMapCustomOpen = get(g:, 'NERDTreeMapCustomOpen', '<CR>')
104+
let g:NERDTreeMapJumpBookmarks = get(g:, 'NERDTreeMapJumpBookmarks', 'gb')
104105
let g:NERDTreeMapActivateNode = get(g:, 'NERDTreeMapActivateNode', 'o')
105106
let g:NERDTreeMapChangeRoot = get(g:, 'NERDTreeMapChangeRoot', 'C')
106107
let g:NERDTreeMapChdir = get(g:, 'NERDTreeMapChdir', 'cd')

0 commit comments

Comments
 (0)