micangl / cmp-vimtex Goto Github PK
View Code? Open in Web Editor NEWVimtex source for nvim-cmp.
License: MIT License
Vimtex source for nvim-cmp.
License: MIT License
I am not sure if this is a bug or not, or if there is anything to be done, but I've noticed that if I open nvim and go to cite something right away, when I cycle through possible completions, it doesn't open up the information menu.
If I exit out and try again, then everything works.
I have also noticed that If I wait 30sec or so before trying to cite something, then everything works.
This is not at all a problem, just wanted to mention it in case that is helpful. Feel free to close immediately if there is nothing to be done.
One other question I had is if it is possible to replace '[article]' or '[book]' etc., with a nerdfont icon. Here is what I tried (first three entries) and seems to work for other sources (I guess nerdfont icons don't work here):
'''
local kind_icons = {
article = "",
book = "",
incollection = "",
Function = "",
Constructor = "",
Text = "",
Method = "",
Field = "",
ETC
}
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) -- Kind icons
vim_item.menu = ({
vimtex = (vim_item.menu ~= nil and vim_item.menu or "[VimTex]"),
nvim_lsp = "[LSP]",
ETC
}
'''
Thanks for the help. Been loving the plugin!
I'm curious if it may make more sense to utilize the new VimTeX lua parser for bib files directly. It has now become quite fast. And after parsing a large file it can be kept in memory.
Thus, even if there would be a delay while parsing for the completion, the delay would be 1) very small, and 2) should only appear once for each session.
I believe this would simplify the cmp-vimtex plugin. Simpler is often better. :)
Hi,
Thanks for the plugin!
Unfortunately, I'm getting persistent crashes/error messages when loading in bibliographies from a couple collaborators: the reason seems to be an unrecognized key in the citation.
The error I'm getting is
stack traceback:
...cal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/parser.lua:64: in function 'format_entry'
...cal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/parser.lua:143: in function 'callback'
...ocal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/timer.lua:72: in function <...ocal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/timer.lua:66>
Error executing vim.schedule lua callback: ...cal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/parser.lua:102: attempt to perform arithmetic on field 'lnum' (a nil value)`
and here's a MWE:
'test.tex'
\begin{document}
\title{this is a title}
\bibliography{test}
\end{document}
'test.bib'
@misc{Harvard-01,
title = "something"
key = {Harvard}
}
Thanks!
I noticed that upon opening a .tex file in neovim, my cwd would change to the same as that of the file itself. I narrowed this behavior down to this plugin - disabling it leaves my cwd unchanged. It is simply added using lazy and, as per the vimtex documentation, vimtex is added as as cmp source for the .tex filetype.
I am unsure where this behavior comes from - but I will be happy to help out if it is not immediately reproducible and turns out to be a more complicated interplay between my plugins.
When installing the plugin using lazy.nvim, I get the following error:
Failed to source `/Users/computer/.local/share/nvim/lazy/cmp-vimtex/after/plugin/cmp_vimtex.lua`
vim/_editor.lua:0: function <SNR>38_NetrwOpenFile[35]..BufNewFile Autocommands for "*"..FileType Autocommands for "tex"..script nvim_exec2() called at FileType Autocommands fo
r "tex":0../Users/computer/.local/share/nvim/lazy/cmp-vimtex/after/plugin/cmp_vimtex.lua: Vim(source):E5113: Error while calling lua chunk: vim/_editor.lua:0: function <SNR>38
_NetrwOpenFile[35]..BufNewFile Autocommands for "*"..FileType Autocommands for "tex"..script nvim_exec2() called at FileType Autocommands for "tex":0../Users/computer/.local/s
hare/nvim/lazy/cmp-vimtex/after/plugin/cmp_vimtex.lua..nvim_exec2() called at /Users/computer/.local/share/nvim/lazy/cmp-vimtex/after/plugin/cmp_vimtex.lua:0: Vim(call):E121:
Undefined variable: b:vimtex
stack traceback:
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...cal/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/source.lua:19: in function 'start_parser'
^I...local/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/init.lua:5: in function '_start_parser'
^I...local/share/nvim/lazy/cmp-vimtex/lua/cmp_vimtex/init.lua:22: in function 'setup'
^I...l/share/nvim/lazy/cmp-vimtex/after/plugin/cmp_vimtex.lua:2: in main chunk
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:481: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:480>
^I[C]: in function 'xpcall'
^I.../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:480: in function 'source'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:439: in function 'source_runtime'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:410: in function 'packadd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:342: in function '_load'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:187: in function 'load'
^I...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:83: in function <...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:72>
^I[C]: in function 'nvim_cmd'
^I...brew/Cellar/neovim/0.9.4/share/nvim/runtime/filetype.lua:25: in function <...brew/Cellar/neovim/0.9.4/share/nvim/runtime/filetype.lua:24>
^I[C]: in function 'nvim_buf_call'
^I...brew/Cellar/neovim/0.9.4/share/nvim/runtime/filetype.lua:24: in function <...brew/Cellar/neovim/0.9.4/share/nvim/runtime/filetype.lua:10>
As you can see, I installed nvim from brew, if that's relevant. I have the vimtex plugin installed and it seems to work fine. I have the nvim-cmp plugin installed by installing zero-lsp nvim with luasnips integration.
I'm trying to figure out how to disable all the regular LaTeX symbol autocompletions:
I'd basically like to only display autocompletion data related to things like labels, bibliographic citations, etc. rather than all the commands from packages!
I tried to read the cmp-vimtex
documentation but could not figure out what the trigger would be. Currently my sources are:
sources = cmp.config.sources {
{ name = 'ultisnips', priority = 1000 },
-- { name = 'omni', priority = 1000 },
{ name = 'vimtex', priority = 750 },
-- { name = 'nvim_lsp', priority = 600 },
-- { name = 'buffer', priority = 500 },
-- { name = 'otter', priority = 500 },
-- { name = 'path', priority = 250 },
},
so I have only enabled ultisnips and vimtex sources. The long list of suggestions goes away if I comment out the vimtex sources line.
Thank you for your efforts,
If I configure cmp-vimex, CmpStatus
shows me the vimtex sources are duplicated
In nvim-cmp lazy.nvim setup, I called the cmp-vimtex plugin as dependencies.
dependencies = {
'hrsh7th/cmp-buffer', -- source for text in buffer
'hrsh7th/cmp-path', -- source for file system path
'hrsh7th/cmp-cmdline', -- source for commandline, [command], [path]
'hrsh7th/cmp-nvim-lsp', -- using LSP for source
'f3fora/cmp-spell', -- source for vim's spellsuggest
'L3MON4D3/LuaSnip', -- snippet engine
'saadparwaiz1/cmp_luasnip', -- using LuaSnip for source
'mstanciu552/cmp-matlab', -- source of matlab
{
'micangl/cmp-vimtex', -- source of vimtex for latex
},
},
Cmp-vimtex loaded just once for unused source names (I didn't load this source to confirm how many this source is called just.)
dependencies = {
'hrsh7th/cmp-buffer', -- source for text in buffer
'hrsh7th/cmp-path', -- source for file system path
'hrsh7th/cmp-cmdline', -- source for commandline, [command], [path]
'hrsh7th/cmp-nvim-lsp', -- using LSP for source
'f3fora/cmp-spell', -- source for vim's spellsuggest
'L3MON4D3/LuaSnip', -- snippet engine
'saadparwaiz1/cmp_luasnip', -- using LuaSnip for source
'mstanciu552/cmp-matlab', -- source of matlab
{
'micangl/cmp-vimtex', -- source of vimtex for latex
config = function ()
require('cmp_vimtex').setup({})
end
},
},
Cmp-vimtex loaded twice as below
Could you know where the vimtex source are called one more?
Using neovim v0.9.4 on Mac OS Sonoma 14.1.1 with nvim-cmp for autompletion, but when I tried to include cmp-vimtex using your README instructions, none of the functionality seems to be working for LaTeX files. Here is my nvim-cmp.lua file:
And my plugins setup file (uses packer for plugin management):
This isn't exactly a bug, it's more likely that I'm missing something in the configuration, but I'll be grateful for any help you might be able to provide!
The autocommand defined here is not triggered if cmp-vimtex is loaded lazily by e.g. lazy.nvim. I think this will be a quite common situation.
A simple, but possibly good solution is to add a check if the current file is already a .tex
file, and to then start the parser immediately.
I would also advice to put all code inside the setup function. That is, require
ing a script should not have a side effect in itself.
Although I can get bib completion to work with a local .bib file, I cannot manage to get the same to work for a global .bib ~/texmf/bibtex/bib/Zotero.bib
which I source with \bibliography{Zotero}
at the end of my latex document. I use this global .bib file for everything and then have a keybinding set up to generate a local .bib file which only includes entries for the citations that occur in the local latex document once it is finished.
I am wondering: how can I get cmp-vimtex to find my global .bib file ~/texmf/bibtex/bib/Zotero.bib
?
Thanks so much for an excellent plugin/extension. I'm so pleased to have it back up and running :)
Given the following lua init file e.g. under ~/test/test.lua
:
local root = vim.fn.fnamemodify("./.lazy", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)
local plugins = {
"hrsh7th/nvim-cmp",
"micangl/cmp-vimtex",
"lervag/vimtex",
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
vim.g.vimtex_cache_root = "."
vim.g.vimtex_cache_persistent = false
vim.cmd([[silent! close]])
vim.cmd.edit("test.tex")
And the following test.tex
:
\documentclass{article}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
Test \cite{gaonkar}
\end{document}
We get the following error message:
Error executing vim.schedule lua callback: .../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:64: attempt to index local 'entry' (a nil value)
stack traceback:
.../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:64: in function 'format_entry'
.../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:143: in function 'callback'
...g/test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/timer.lua:72: in function <...g/test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/timer.lua:66>
Here I tried to explain whats up. Basically I wrote some snippets (\begin snippet) for example, and when the cmp-vimtex completes the environment name it closes the brace. I dont need this brace. Or do I? I just want to know what I am doing wrong.
I've just moved over to using cmp-vimtex from cmp-omni. I'm liking it better, and there are a few hick-up's I'm trying to fix. I'd like to see the citation information the plugin provides, but I have a custom formatting for my cmp sources:
cmp.setup({
...
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.kind = string.format('%s %s', icons.kind_icons[vim_item.kind], vim_item.kind) -- This concatenates the icons with the name of the item kind
vim_item.menu = ({
nvim_lsp = "[Lsp]",
luasnip = "[Snip]",
path = "[Path]",
nerdfont = '[Nerd]',
buffer = "[Buf]",
spell = "[Spell]",
calc = "[Calc]",
vimtex = "[Vimtex]",
git = "[Git]",
Variable = "[Var]",
Todos = "[Comment]",
})[entry.source.name]
return vim_item
end,
}
...
})
I have done require('cmp-vimtex').setup(...) as well, but this seems to override it. I think I need to put something here to say that for cmp-vimtex, use its custom formatting. Any ideas on how to do that?
In the new branch test_highlighting
is available a feature I had wanted to implement for some time. Basically, it highlights the bibliographic keys in the documentation windows:
I haven't written the documentation yet. This is the relevant part of the configuration:
local defaults = {
additional_information = {
bib_highlighting = true,
highlight_colors = {
default_group = "Normal", -- Highlight group for most of the keys (in my config it's the yellow part)
important_group = "IncSearch", -- Highlight group to distinguish the most important keys
default = { -- Eventually, color codes can be specified
fg = "",
bg = "",
},
important = {
fg = "",
bg = "",
},
},
highlight_links = { -- This sets, for each key, if "Default" or "Important" is used.
-- Normal highlight groups can be used too.
-- Bibtex
Address = "Default",
Annote = "Default",
Author = "Important",
Booktitle = "Default",
Email = "Default",
Chapter = "Default",
Crossref = "Default",
Doi = "Default",
Edition = "Default",
Editor = "Default",
Howpublished = "Default",
Institution = "Default",
Journal = "Default",
Key = "Default",
Month = "Default",
Note = "Default",
Number = "Default",
Organization = "Default",
Pages = "Default",
Publisher = "Default",
School = "Default",
Series = "Default",
Title = "Important",
Type = "Default",
Volume = "Default",
Year = "Default",
-- Biblatex
Isbn = "Default",
-- cmp-vimtex-specific keys
File = "Default",
Lnum = "Default",
Cite = "Default",
},
},
}
This may interest @lervag and @benbrastmckie.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.