preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.12k stars 486 forks source link

Add JumpToNearbyTag functionality #780

Closed raven42 closed 3 years ago

raven42 commented 3 years ago

Closes #779

Updated functions:

s:GetNearbyTag() - Allow for a direction parameter to be passed into the routine. This will allow for a forward or backward search. It will default to a backward search line the current behavior if the a:direction parameter is not used.

s:JumpToTag() - Allow for an optional parameter to be passed in to specify the tag instead of using the tag under the cursor on the current line. This also allows this routine to be executed from the file window instead of the tagbar window. Assume autoclose=0 if passing in the tag.

Add new functions:

s:JumpToNearbyTag() - This routine will do a forward or backward search for the nearst tag using the GetNearbyTag() with the new direction field, then call the JumpToTag() with the tag we found.

tagbar#jumpToNextTag() - New public facing wrapper routine around the JumpToNearbyTag() routine. Optionally take in a:lnum and a:search_method to be used in other routines. If a:lnum is not present, then the line number will search from the next or previous line depending on the a:direction value.

TODO:

raven42 commented 3 years ago

Not providing a default keymap as this affects the actual file window and we don't want to change something the user may already have set. The function calls and new commands will be enough and the user can provide their own keymapping in their .vimrc to provide the correct mapping.

Recommended keymap:

nnoremap t[ :TagbarJumpPrev<CR>
nnoremap t] :TagbarJumpNext<CR>