Vimtex: Vimtex citation completion is counter-productively general

Created on 3 Dec 2018  路  30Comments  路  Source: lervag/vimtex

This issue may be related to #1162, and indeed reading it helped me better understand my own as I've rarely ever heard the word 'omnicompletion' before.

My problem is the following: when I type something like

\cite{Sut<c-x><c-o>

I get an autocompletion popup with all citation strings somehow matching Sut, sorted on some unfathomable criterion. The first match will be inserted instead of the old Sut. This popup, once open, behaves more naively in that it starts matching from the start of the string (after backspacing the suggestion for example). Because of the strange sorting, it's very unlikely a key that actually starts with Sut will be inserted.

I keep simple citation keys, usually of the format FirstAuthorYear. I like auto-completion because it can help me find hard-to-spell names, or figure out the exact year of the citation. This is a smaller need than searching on title, for example, which the current behaviour _does_ lend itself to very nicely.

My question then: is there a way to arrive at a more simple behaviour? One that simple matches on the citation key, for example. Or at least one that sorts on a different criterion, e.g. weighting citation key match much higher so matching citation keys float up. As far as I can tell, the current sorting is according to the order in the bib file, which is unlikely to reflect any sort of relevance (like when I search on author name, a first author match is more likely to be useful to me).

Most helpful comment

I use both:

Complete bibkeys

I have a ctags file (kept up-to-date with gutentags) and complete bibkeys with

\cite{Sut<c-x><c-[>

(also slightly faster than omni completion)

Complete citation without knowing the bibkey

When I cannot recall the bibkey but a name of an author or a distinctive word in the title, I use

\cite{some_author_not_necessarily_the_first<c-x><c-o>

provided by vimtex. Therefore, I would appreciate if the old omni completion is not removed.

All 30 comments

I very much agree with your desire to complete based on bibkeys. I'm pushing an update now with an option, g:vimtex_complete_bib_simple, that should implement this for you. Set it to 1 to enable it. I'm keeping the old behaviour as standard so as not to surprise anyone.

I'm also pushing an update to the completion menu descriptions that I think is an improvement. I'm considering to remove the type part, e.g. [a] and similar, as I think it provides little value. Opinions are welcome (@kiryph @clason may have opinions here?).

Actually, I slightly(!) prefer the old behavior -- for me, the key doesn't add any information beyond the authors, year, and title that were shown already. (I was very sad, by the way, when neovim-qt changed the popup menu and couldn't print the full information as the classical one anymore.) And I frequently have problems with the popup menu being truncated due to opening on the far right side of the buffer. But if the change helps sorting matches by key before other matches, I'd understand -- that is a reasonable expectation.

Also, I found the type part (again) slightly useful for the cases where there is a very prolific author, I want to cite their book, and the titles are truncated (see above).

@lervag, amazing, thanks for the swiftness and willingness. I also prefer the simpler completion menu, type did indeed add pretty little.

Out of curiosity I'm still planning on having a look at a sorting option and maybe proposing one. It would have the benefit of being only a single option, offering decent standard behaviour while still allowing some flexibility. And it would effectively do the same as bib_simple, albeit with some overhead.

Anyway, greatly appreciated!

I use both:

Complete bibkeys

I have a ctags file (kept up-to-date with gutentags) and complete bibkeys with

\cite{Sut<c-x><c-[>

(also slightly faster than omni completion)

Complete citation without knowing the bibkey

When I cannot recall the bibkey but a name of an author or a distinctive word in the title, I use

\cite{some_author_not_necessarily_the_first<c-x><c-o>

provided by vimtex. Therefore, I would appreciate if the old omni completion is not removed.

Actually, I slightly(!) prefer the old behavior

@clason Are you talking about the completion menu here? Personally, I strongly prefer the new menu, because it felt wrong now showing a list of what was actually completed (the keys).

Completion menu entry

Perhaps it would be sensible with a format option? Something like:

let g:vimtex_complete_bib_menu_format = '[<type>] <author> (<year>), "<title>"'

Where the fields may have some default values when missing, e.g. <author> = Unknown and <year> = ?. That would allow one to define a style that works for ones personal workflow?

Completion filtering

@kiryph I never intended to remove the old behaviour, only to allow a new behaviour that might be more natural to a lot of people (myself included). I've added an option g:vimtex_complete_bib_simple that may be enabled for the new type of completion filtering (i.e. filter only on bibkeys).

Regarding sorting, @rubenvereecken, I would not mind to consider a PR for some more sensible sorting. As of now, the entries are not sorted at all.

@lervag, Yes, I meant the completion menu. I found it liberating that I didn't have to remember (and care about) the keys anymore, so I just let vimtex/bibtex do their thing :) But if you feel strongly, that is a good argument for the change.

Regarding the menu: It also matters which (PUM) field is used for each (complete) field -- abbr, menu, word, etc. -- since that is what ncm2 matches (possibly differently!) on. So I'm not sure a format option is feasible.

Ok, thanks. I've pushed a minor update now that makes things ready for allowing custom formats (if that should be desirable).

In the meantime, I'm currently setting word to the bibkey and menu to the formatted string. I think this should allow you to filter for author, year and title in the menu string with ncm2, right?

OK, then I'll remove the abbr from my matcher. Yes, that should allow different matching (by prefix) on the key and (fuzzy) on the string. Would it be easy to put the full author list in a different field (not shown, or shown in the end)? I sometimes remember papers by third or fourth author only and only realize later why they don't show up in the complete menu...

Hmm, yes, I think it could be done. I'll check and submit a patch immediately, if possible.

Oh, and after the update I don't see any years anymore -- it's only Author (?), "Title".

Strange. It looks good to me. The relevant code is in autoload/vimtex/complete.vim line 133. Can you see if you spot the problem?

Yes, I was using date in the bibtex file instead of year, which is also valid (and preferred for biblatex).

Hmm. I did not change anything that should affect this. Note that the menu information is parsed by running bibtex on a temporary file that includes all references. I guess the style used does not understand the date field.

Most styles should have this as a standard alias. Which style are you using for parsing?

(You're right that it didn't print this before; but since it just omitted the date including the parentheses, I didn't notice.)

I use this style:
https://github.com/lervag/vimtex/blob/master/autoload/vimtex/vimcomplete.bst

If you know how to update this to get the year from the date field, then that would be useful. I'm not really well versed in writing bst files.

Done: #1267

Thanks, @clason! May I assume that this issue is now fully resolved?

If the issue with the menu fields is [wontfix] (which is fine), and you don't want to remove the entry type (which I'd be OK with), then yes.

Not sure I understand. Could you specify more precisely what the issue with the menu field is?

Reg. the entry type, I decided to keep it and instead add an option that allows me to remove it for myself. It feels better, because the changes for most people that keep the default settings is now minimal and (IMHO) justifyable, and if one wants one may change the menu format with a relatively simple fomat string.

Sorry, I meant precisely this change -- I didn't realize you already pushed a commit to make it configurable. I'll check it out and see if it works with my ncm2 workflow (which should be the case if you've only touched the menu format).

Great, thanks. Let me know if you have further suggestions for improving this.

I just looked at the new documentation -- did I understand it correctly that the cite key is now hard coded and can't be removed via the new format string? (Not a big deal, but just to make sure.)

Yes, the cite key (or bibkey as I've denoted it) is hardcoded as the completion word and the abbreviation is gone. I feel this makes sense, because it feels "wrong" to not be able to see whatever is actually being completed. I could add one more option for this as well, if you feel strongly about it. If so, we should think if there might be a more flexible way of defining this. I'm thinking perhaps a config dictionary that combines the recent options through three keys: simple, menu_fmt and abbr_fmt. The former two are as defined earlier in this thread, and the latter could be added to allow a nonempty abbreviation. If any of the format keys were missing, the completion entries would leave these out entirely, and by default, the abbreviation key would be empty.

I certainly don't feel strongly enough about it to create more work for you than I already have...

But being able to format the complete-items would be quite powerful. Long term, I could see the following being useful:

  1. encode the (bibtex) type (or the label type for \ref{) in kind -- not sure if there is a client yet that actually uses this, but different coloring for books and articles could be a nice compromise.
  2. put the complete bibtex entry (or formated reference) into info as a preview.

But that's another issue. Your suggestion sounds very good to me (sane defaults + configurability = win!) Maybe it makes sense to have a similar configuration for the other complete patterns (commands, labels, files)?

What the heck, I decided to just improve this as I was thinking. You can now set the abbr_fmt if you want. This way you can get the old style back, if you want, with something like this:

let g:vimtex_complete_bib = {
      \ 'abbr_fmt' : '[@type] @author_short (@year)',
      \ 'menu_fmt' : '@title',
      \}

NB @rubenvereecken I've changed the option names now. Instead of g:vimtex_complete_bib_simple, you should now add something like this: let g:vimtex_complete_bib = {'simple' : 1}, or if you also want to customize the formats, see above and read the docs.

Cool, thank you very much!

Though it makes sense to show the bibkeys in the menu, but sometimes these keys do not provide any useful information, other than occupy much space of the window. As for as I know, many people, in mathematics, do copy the bib item from mathscinet or zbmath. The bib keys there in the database are of the form like zbMATH05296030 or MR0354654. People may not want to see these meaningless keys when do completion. On the other hand, the old style is more convenient.

@haoyun Many people in maths/physics also maintain their bibfiles more carefully and specifies keys according to some "template", e.g. "author-year". In any case, I do not really understand your comment. Are you suggesting any changes to vimtex?

Sorry I didn't explain it clearly. I just wanted to say that, the old style, without the bib keys in the menu, might be better when people do not want to see these keys. It is more practical to choose from a list with only the author and title information and without the (sometimes) useless keys.

Ah, ok. Well, the old style is still available as described above. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vanabel picture vanabel  路  6Comments

carloabelli picture carloabelli  路  3Comments

David-Fu picture David-Fu  路  5Comments

lervag picture lervag  路  5Comments

chakravala picture chakravala  路  5Comments