rafaqz / citation.vim

Zotero and bibtex citations for Vim
MIT License
96 stars 7 forks source link

Opening file from citation key sometimes oppens another paper #28

Closed Djoop closed 4 years ago

Djoop commented 4 years ago

Hi and thanks for the plugin. I mainly use it to open papers from the reference key, using the "co" shortcut, which works well most of the time. However, it happens sometimes that the paper which is opened is not the one corresponding to the citation. It is, however, often another paper from the same author. I'm not sure what is the exact criterion to reproduce this. Should it be expected due to the "hacking" nature of the plugin, or is it a bug? Is there an implicit requirement on the citation keys to get this functionality to work properly (I use betterbibtex for the keys, but I also have order keys which follow a different rule, could it be the cause of the problem?)

rafaqz commented 4 years ago

Basically Unite.vim is doing a string match on the whole string entries you see in the Unite split. The closest match will be returned. This plugin is actually not involved in that, except for making the list of entries for Unite.

If your reference keys are truly unique strings it will always work. It may not work if some keys are subsets of other keys that come first in the list. Normally I use autherYEARTitle and find it very hard to ever have two keys where one is a subset of the other. But I guess it's possible to happen if they have very similar named papers in the same year, like smith2010In and smith2010Inside, where co on smith2020In could return either one depending on which comes first.

You could improve it by using something like we use to do the fulltext search command and doing an exact search internally, but I haven't tried that and will never have time to.

I would say try to pick a more unique key style and redo your betterbibtex database, but it will kill all of your old papers...

Other keys following a different rule may be the problem too, it's hard to say.

rafaqz commented 4 years ago

what is your key format by the way?

Djoop commented 4 years ago

Thank you for the quick answer, and sorry if the problem actually comes from Unite. I think I have exactly the problem you are describing. I switched to the "nameYYYYBeginningOfTitle" format, but I have older entries in "authorYYYY" format. I checked again and the problem indeed seems to appear only in the cases where one key is a prefix of another key. I did not regenerated all the key so far to keep compatibility, but at least I know exactly what the problem is now, so I can do it on a case by case basis. Sorting the list to get exact matches first would indeed be better, but I don't really have time to look into it at the moment, so I will keep it like that for now and close the ticket, thank you!

rafaqz commented 4 years ago

Great that sounds like the problem!

Maybe we should warn in the readme that simple keys like authorYYYY aren't enough.