-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to Autocomplete Citations with Nvim-Cmp + Cmp-Omni #2596
Comments
First: I'm sure we will be able to figure this out. But I'm sorry that I don't have the time to help much right now. I'll follow up as soon as possible. In the meantime, some minor comments:
|
Thanks so much! I have changed my cmp.lua file to include I have also attempted the test you mentioned, including the minimal.lua
minimal.tex
test.bib
ErrorAlthough I could build the pdf just fine with my normal config,
Hitting ENTER opened the file with syntax highlighting, but the autocomplete menus did not seem to work in any capacity including Thanks again for the tips! I really appreciate the help :) |
Still don't have quite enough time to go deep, sorry! But some quick replies:
Sorry, I did not mean you should remove the Tree-sitter plugin. Only to disable Tree-sitter highlights for VimTeX. Please read Also, notice, for VimTeX syntax highlighting, you should remove Now, for your example
This error is due to your use of -- vim.opt.runtimepath:prepend "PATH/nvim-lua/plenary.nvim"
-- vim.opt.runtimepath:prepend "PATH/hrsh7th/nvim-cmp"
-- vim.opt.runtimepath:prepend "PATH/hrsh7th/cmp-nvim-lsp"
-- vim.opt.runtimepath:prepend "PATH/hrsh7th/cmp-buffer"
-- vim.opt.runtimepath:prepend "PATH/hrsh7th/cmp-omni"
-- vim.opt.runtimepath:prepend "PATH/neovim/nvim-lspconfig"
-- vim.opt.runtimepath:prepend "PATH/williamboman/mason.nvim"
-- vim.opt.runtimepath:prepend "PATH/williamboman/mason-lspconfig.nvim"
vim.opt.runtimepath:prepend "PATH/vimtex"
vim.opt.runtimepath:append "PATH/vimtex/after"
vim.cmd[[filetype plugin indent on]]
local cmp = require("cmp")
cmp.setup({
sources = cmp.config.sources({
{ name = "omni" },
{ name = "nvim_lsp" },
{ name = "buffer", keyword_length = 3 },
}),
})
vim.g.vimtex_view_method = "zathura"
-- vim.g.vimtex_syntax_enabled = 0
-- I would also recommend to keep the quickfix stuff enabled!
-- vim.g.vimtex_quickfix_enabled = 0 Here |
Thanks so much for this! I've also been busy travelling but now returning to try to straighten this out before diving back into work. I've fixed up my minimal.tex as follows: \documentclass[11pt]{article}
\usepackage[a4paper, margin=4cm]{geometry}
\usepackage[english]{babel}
\begin{document}
\title{\sc TITLE}
\author{\it Benjamin Brast-McKie}
\date{\today}
\maketitle
\thispagestyle{empty}
\begin{abstract}
\noindent
ABSTRACT
\end{abstract}
\section{Introduction}\label{Intro}
\cite{Acharya2013}
\bibliographystyle{plain}
\bibliography{minimal}
\thispagestyle{empty}
\end{document} I've also included a minimal.bib as follows: @article{Acharya2013,
address = {{The Netherlands}},
author = {Acharya, Diwakar},
journal = {Indo-Iranian Journal},
number = {1},
pages = {3--39},
publisher = {{Brill}},
title = {N\'eti N\'eti {{Meaning}} and {{Function}} of an
{{Enigmatic Phrase}} in the
{{G\=argya-Aj\=ata\'satru}} Dialogue of {{B\d{r}had
\=Ara\d{n}yaka Upani\d{s}ad II}}.1 and {{II}}.3},
volume = {56},
year = {2013},
abstract = {This article argues that it is necessary to recognise
Sections II.1 and II.3 of the B\d{r}had
\=Ara\d{n}yaka Upani\d{s}ad as one discourse. Since
nobody among traditional or modern scholars has paid
attention to this structure, many problems have been
neither seen nor solved. This article does so, and
further, exposes textual problems embedded there and
analyses them. In this very discourse the expression
n\'eti n\'eti is introduced as an \=ade\'sa.
Therefore, this article investigates the meaning and
function of this expression there. This article also
muses on possible implications of the entire
discourse of G\=argya and Aj\=ata\'satru.},
doi = {10.1163/001972412-620402},
issn = {0019-7246},
} Lastly, I changed the minimal.lua as you suggested: vim.opt.runtimepath:prepend "/home/benjamin/.local/share/nvim/site/pack/packer/start/cmp-omni"
vim.opt.runtimepath:append "/home/benjamin/.local/share/nvim/site/pack/packer/start/cmp-omni/after"
vim.opt.runtimepath:prepend "/home/benjamin/.local/share/nvim/site/pack/packer/start/nvim-cmp"
vim.opt.runtimepath:append "/home/benjamin/.local/share/nvim/site/pack/packer/start/nvim-cmp/after"
vim.opt.runtimepath:prepend "/home/benjamin/.local/share/nvim/site/pack/packer/start/vimtex"
vim.opt.runtimepath:append "/home/benjamin/.local/share/nvim/site/pack/packer/start/vimtex/after"
vim.cmd[[filetype plugin indent on]]
local cmp = require("cmp")
cmp.setup({
sources = cmp.config.sources({
{ name = "omni" },
{ name = "nvim_lsp" },
{ name = "buffer", keyword_length = 3 },
}),
})
vim.g.vimtex_view_method = "zathura" And indeed, the VimTex functionality seems to be back up and running. What I'm wondering is how to proceed. How can I use this minimal example to detect what is going wrong? Am I to slowly restore my config piece by piece looking for where things break? This is new territory for me, so I'm not sure if there are standard procedures for such things. As an after thought... I found the following upon checking health:
I have tried installing Thanks again for all of your help. I'm definitely getting closer! |
Cool. That's good, and implies that your problems are due to some issue with your configuration or similar.
Well, that's the good question. First, you need a simple way to test if things are not working. E.g., start with your current full config and a minimal LaTeX project and verify that you can still reproduce your problem. Now, either:
I typically go with 2 in such cases, and I find it usually doesn't take too long. It can be boring, of course. I tend to comment out/remove big chunks at a time, sort of like doing a bisection search.
If you don't know that you need
Did you remember to refresh your packages (e.g. |
I think I found the problem, and I suppose as is often the case, it is a lot more basic than I was worried it might be. The problem is fixed on my normal config so long as the .bib file is in the working folder. However, I prefer to draw on my full Zotero .bib file which lives in texmf/bibtex/bib and stays updated as I add papers to it etc. Is there a way to have my cake and eat it too? I'd love to have the VimTex autocompletion working for citations from my full bib file. Any thoughts would be greatly appreciated. |
Ah, yes. First, I believe it should be possible to create a minimal example of the situation you are describing; if you do, then I can look into it more specifically and perhaps see if it is possible to fix things. However, as a workaround, I believe you can e.g. use an absolute path to the bibliography. I think the problem is that VimTeX can't locate the bibliography file. That is, you have Notice, though, that this is quite a lot more complicated. The relevant code for finding the bib files is here: vimtex/autoload/vimtex/bib.vim Lines 7 to 41 in bd0173e
|
For good measure, I tried putting a copy of my full .bib file in the project folder for my minimal example, and no dice. The .bib file is huge (14976 lines), so started deleting chunks. I found that it works if I delete everything after line 13000, and stops working if I delete everything after line 13500 (I didn't persist to find the exact maximum number of lines, or entries as it may be, that it will accommodate). So the length looks to be the problem since I'm using my standard config for all of this, and got the same cut-off when using the minimal config. Next I put a shortened version of my full .bib file in the /texmf/bibtex/bib directory, and indeed VimTex can draw from it no problem. So the length does seem to be the issue. Do you know why VimTex struggles to handle such a big .bib file (assuming that it is VimTex's fault)? Is there anything I can do to fix that? I simply love the elegance of being able to add new citations with the Zotero browser plugin which updates my master .bib file automatically so that I can cite those papers immediately without ever having to edit a .bib file. |
Perhaps there is something bad in your bib file that breaks the parsing? If you delete e.g. the first 2000 lines (make sure to not break a bib entry, of course) - does it work now?
No, and I don't think VimTeX actually do struggle here. There's a test file that's even larger than yours: huge.bib. It is used in some tests and it is handled properly.
Yes, I also like the integration between Zotero and VimTeX. However, I stopped having a master bib file at some time. Instead, I export smaller collections relevant to the current paper/stuff I'm working on, and I export it to the particular project I'm working on. I found that works better for me, especially when I collaborate with other people. |
Good thought! I've tried deleting the first 2k lines, and that also makes it work just fine. So the .bib file must be error free. I'm glad to know that VimTex works for large .bib files. Maybe it is Out of curiosity, when you export a collection for some project but then need to add another paper to it, what does that entail? I suppose you'd have to add the new paper to Zotero via the browser plugin, then include it in the collection, then export that collection again? Or will the collection auto update? If the latter, then I guess the only extra step is creating and exporting a collection for each project and adding new papers to the relevant collection in addition to adding them to Zotero. I might give this a try until I can get my full .bib to work properly. I can definitely see how this would be better for collaboration. |
I have been following this discussion with interest. @benbrastmckie has asked about how to work between local and global bib files. I wanted to note that there is another nvim plugin that is starting to develop on the side of fuzzy-find citations. In addition, I have asked the author for functionality that splits local and global files. For example:
The second question also deals with the recent discussion about how we get references from a global bib file and move that reference to a local file. So my workflow was to basically use Telescope to fuzzy find a reference, then allow me to yank that reference. I guess you could develop scripts for this as well. Just to be clear, I was turning to Telescope because I was somewhat frustrated by the inability to easily set up fuzzy find on citations (as you would get if you used Sublime Text or similar). To me, what is the optimal workflow?
|
I'm not 100% convinced. If you don't mind, could you perhaps share a minimal LaTeX project and your large
I also find it hard to believe the problem is with these.
The same workflow you already outlined, except that you must add papers to the specified (sub)collections in Zotero. If you right-click on a subcollection, then choose "Export collection" and use "Better BibTeX", you will have the choice to export and continuously update with "Keep updated". Many references are relevant for several papers/manuscripts; I just copy the items between collections as necessary. I don't mind overlap between the collections.
Yes, more or less. With the zotero extension for Firefox, I get a menu like this when I save items: I just choose which collection to save to. It stays the same on subsequent saves, so I only need to change the collection every once in a while. |
Thanks for sharing!
I already mentioned that I prefer to use Zotero to update local bib files. I don't see a reason to have both a full bibliographic collection in Zotero and a mirrored bib file version. But: We each have our own preferences, and that's fine!
I find writing But, again, I don't mind that people want and choose other workflows! I'm glad there are more alternatives available that allows these differing workflows as well :) |
@lervag Here is the directory where I have my minimal.lua, minimal.tex, and minimal.bib file which is identical to the Zotero.bib file that lives in texmf/bibtex/bib: https://github.com/benbrastmckie/.config/tree/lua/nvim/minimal Thanks for checking it out, and for the notes on your workflow. I think I'll institute that for the time being. @ThSGM Thanks for the links and for promoting those feature requests. Perhaps you are already aware of bibexport but this is what I have been using to generate a local .bib file from my master .bib file. You can look up further details with
My previous workflow was to:
I suppose what you are proposing is that this process happen in the background as you cite new papers that have not already been cited in the current file. Plus fuzzy finding. Seems like a great idea :) However, the workflow that @lervag describes also strikes me as a natural way to proceed. It does mean a little more care must go into maintaining a collection for each paper, something that I am not accustomed to, using collections instead to organise papers by subject-matter (not that these are incompatible). |
I think @lervag noted the problem in this workflow, which is the same problem I encounter when collaborating with many people---which is that you need to create the local bib files as you are editing collaboratively. This often occurs over something like Overleaf or via version control.
From a VimTeX perspective, I guess the answer is that using a master bib file would then allow you to interface directly with the bib file. So here is the dream workflow:
Also, it may interest you, if you weren't already aware of gscholar. So you can essentially run a script to output the first paper on Google Scholar under a keyword. (I'm not sure how to do this in vim but I assume there is a way). I also tried https://github.com/mreppen/vim-scholar but had mixed results. The dream would be a hotkey that then gives you a listing of say, 10 articles. Then you can select which one you want. Then it automatically inserts the intro into your local bib file. |
Thanks, I'll check it out and get back to you!
Yes, in these cases I often tend to have one separate personal bib file for the project with which I work as previously indicated. I then synchronize the contents with the shared "collaborative" bib file after doing a writing session.
Ok, I can see that this workflow may be useful. Still, I believe workflows like this may be equally useful as separate bib-specific plugins. Further, I'm quite at a lack of time, and so when prioritizing between issues I want to follow up, I'm sorry to say I will not prioritize this personally.
Thanks for sharing! |
It seems the issue was that you had an entry that was not correctly parsed: @article{Thieme1968,
title = {\=Ade\'sa},
author = {Thieme, Paul},
year = {1968},
journal = {M\'elanges d' indianisme: \`a la m\'emoire de Louis Renou},
pages = {pp.\textasciitilde 715-723}
} Specifically, the tex codes I believe this is fixed now, could you test? |
That fixed it! Thanks so much for the help. Out of curiosity, how were you able to locate that error? I'm interested to improve my own troubleshooting skills. |
Glad to hear it!
I downloaded your files, then I created a minimal set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable
silent edit minimal.tex I started neovim with Now I added a few To speed up the test loop, I automate more of the testing with the following set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable
silent edit minimal.tex
let s:candidates = vimtex#test#completion('\cite{', '')
echo len(s:candidates)
quitall! |
Thanks so much! |
Description
I've been having troubles trying to get VimTex + nvim-cmp + cmp-omni to work well in Lua, and have been reading everything I can find to try to sort out the problem. I've followed the VimTex help docs and believe that I have it all configured in the right way, and get most of the functionality that I'm looking for, just no access to my .bib file in the autocomplete menu, and so I can't autocomplete citations.
Here are some other relevant issues:
Steps to reproduce
Here is a MWE which I named minimal.lua
I was able to reproduce the observations above by running
nvim -u minimal.lua minimal.tex
. In case it is helpful, I also created a MW branch of my full config (I'm on the Lua branch until I can get full functionality out of VimTex). The same observations given above continue to apply. Any help or pointers about how to test the problem would be greatly appreciated.NOTE: My config includes some files for tmux, alacrity, etc., so as to provide a complete package for those just starting off (i.e., academics with no experience working with the terminal etc., and so are stuck inside TexShop or Overleaf). I have not removed all of these files from the MWE since I can't imagine they are causing the problem.
Expected behavior
I expect to be able to autocomplete citations in the manner that I had working for my vimscript config.
Actual behavior
Here are some observations:
Do you use a latexmkrc file?
No
VimtexInfo
The text was updated successfully, but these errors were encountered: