lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.52k stars 389 forks source link

Search within bibliography entry titles for completion #887

Closed wbthomason closed 7 years ago

wbthomason commented 7 years ago

It would be useful for vimtex's citation completing support to include the titles of bibliography entries in the text searched for a completion match. This would e.g. make it easier to cite a paper based on the topic or title rather than having to look up the author.

I've looked briefly at adding this to https://github.com/lervag/vimtex/blob/master/autoload/vimtex/complete.vim#L126, and would be willing to make a PR for this feature if it's something that's desirable for vimtex. I suspect that it would be a simple change, but my vimscript-fu is weak, and so I haven't gotten it working yet.

lervag commented 7 years ago

This feature is already there. But it won't work too well with other completion engines. Vimtex provides an omni completion where the leading part that is to be completed is tried as a regular expression against the bibliography entries. E.g., with the following bib entry:

@Article{Sussman94,
  author  = {M. Sussman and P. Smereka and S. Osher},
  title   = {A level set approach for computing solutions to
             incompressible two-phase flow},
  journal = {Journal of Computational Physics},
  volume  = {114},
  pages   = {146-159},
  year    = {1994},
}

You can complete with \cite{A level set<c-x><c-o>, and it will complete the Sussman94 entry.

lervag commented 7 years ago

As an extra note: To make this feature work smooth with autocompletion plugins (neocomplete/deoplete/youcompleteme/nvimcompletionmanager/etc) is not possible (I think), because the typed text that you want to complete does not correspond to the desired resulting text. However, if you do not automatically insert autocompleted entries, the above mentioned approach should still work.

wbthomason commented 7 years ago

Ah, this would explain why I couldn't seem to make this sort of completion work. Thank you for the tip!

lervag commented 7 years ago

No problem :)