tagbar icon indicating copy to clipboard operation
tagbar copied to clipboard

[Feature] Allow tags jumping with no need to open the tags panel first

Open pidgeon777 opened this issue 1 year ago • 5 comments

Currently, to use the TagbarJumpNext and TagbarJumpPrev commands, you need to open the tagbar panel first.

It would be great to allow jumping to the next/previous tag without opening the tagbar panel first, eventually by setting a custom option to enable this behaviour.

pidgeon777 avatar Feb 02 '23 13:02 pidgeon777

This can be done a little bit indirectly. The reason it is not working for you without opening the tagbar window is because the file has not yet been scanned for tags. This is actually an optimization that is in the plugin to avoid using extra resources if not in use. I.E. there is no reason to load the tags for a file unless you open the tagbar window or are using the tags.

To trigger a call to scan the file for tags, you can add the following to your .vimrc somewhere after the file has loaded.

call tagbar#Update()

This should trigger scanning the file for tags, and thus the :TagbarJumpNext / :TagbarJumpPrev command should work.

raven42 avatar Feb 23 '23 13:02 raven42

call tagbar#Update() leads to an error:

Errore/i eseguendo function tagbar#Update[1]..<SNR>104_AutoUpdate[38]..<SNR>104_IsValidFile:
riga   29:
E121: Undefined variable: s:known_types
E116: Argomenti non validi per la funzione: has_key

pidgeon777 avatar Feb 23 '23 14:02 pidgeon777

Hmm... are you by chance using vim 9? I've seen a similar error on a test setup with vim 9 that I have that I haven't been able to really track down yet. From what I can tell it seems to be something with vim 9 doing the initial load a little differently than vim 8, where calling a tagbar function inside the .vimrc causes a similar error, but once vim is fully loaded, then calling the same function seems to work just fine.

raven42 avatar Feb 23 '23 14:02 raven42

I'm using Neovim version v0.8.3 stable.

pidgeon777 avatar Feb 23 '23 14:02 pidgeon777

hm. Ok. could be something similar. I'll try to dig into it more and see if I can figure anything out. But as of now, that is about the only way I can think of to automatically have the :TagbarJump... commands work.

raven42 avatar Feb 23 '23 15:02 raven42