2

In large code bases, there can be multiple hits for an identifier. Sometimes dozens. When you look up a tag, the first choice in the list is often some false positive you don't want.

The user experience for finding the right tag is quite poor; you have to scroll through some list (in one direction only) where the location you want might be #37 or whatever.

Then, if you chase that same tag again, it appears in the same #37 position in the same list.

Is there a way to:

  • have recent matches go to the top of the list? So if you jump to the same definition twice, the second time it should be in the #1 position? (Such that the recently-used info is saved in Vim sessions, ideally.)

  • prioritize the matches by whether those files are currently open in a buffer? E.g. suppose there are 117 matches for a tag, but three of them land in files that are currently open in buffers: those three should be at the top. (And perhaps if exactly one match occurs in a buffered file, it should just bypass the list and jump to that one.)

3 Answers 3

1

prioritize the matches by whether those files are currently open in a buffer

This should be doable by setting tagfunc. call taglist() and sort based on if files are open.

4
  • That seems very promising. In fact this tagfunc completely abstracts the search. I will look into what it would take for it to keep a recent list, in such a way that the list will persist with Vim sessions too.
    – Kaz
    May 30, 2023 at 23:25
  • Alas, tagfunc appears not to be implemented yet in Vim 8, which is what you get on Ubuntu 18, which I'm still using.
    – Kaz
    May 31, 2023 at 1:11
  • 1
    You can install a newer Vim.
    – romainl
    May 31, 2023 at 7:59
  • 1
    ... or a newer Ubuntu.
    – Friedrich
    Jun 1, 2023 at 10:59
1

The :ltag command populates the location list with the list of matching tags. This makes it easier to browse the list.

Note: The location list feature was originally added to Vim to support this command.

1
  • Any way to get it into quickfix list instead?
    – balki
    Jun 2, 2023 at 21:04
0

I can recommend you some Fuzzy plugins like:

They have provider from tags that can be filtered using fuzzy logic.

In Fzf you can:

  • Use the :Tags command to list the project tags and fuzzy search them.
  • Use the :BTags command to list the buffer tags and fuzzy search them.

In CtrlP you can:

  • Use the :CtrlPTag command to list the project tags and fuzzy search them.
  • Use the :CtrlPBufTagAll command to list the buffers tags and fuzzy search them.

In vim-clap you can:

  • Use the :Clap proj_tags command to list the project tags and fuzzy search them.

enter image description here

In Telescope you can:

  • Use the :Telescope tags command to list the project tags and fuzzy search them.
  • Use the :Telescope current_buffer_tags command to list the buffer tags and fuzzy search them.

This is not fully answer your question but maybe an extended version of the Fzf or vim-clap provider would be the way to go to fulfill your demands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.