0

I tried to migrate fomr packer.nvim to lazy.nvim and I encounter problem with deoplete. With packer is triggered on every document and .tex files. With Lazy.nvim is not.

I appreciate any help!

Here is my nvim tree:

 .
├──  init.lua
├──  lazy-lock.json
└──  lua
   └──  mafsi
      ├──  lazy.lua
      └──  plugins
         ├──  colorscheme.lua
         ├──  deoplete.lua
         └──  vimtex.lua

Here are my files:

init.lua

-- Set Neovim's runtime path to include the config directory
vim.cmd("set runtimepath^=~/.config/nvim")

-- Set Neovim's pack path to include the config directory
vim.cmd("set packpath^=~/.config/nvim")

vim.g.python3_host_prog = '/usr/local/bin/python3'

vim.o.completeopt = "noinsert,menuone,noselect"

require("mafsi.lazy")

lazy.lua

local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup("mafsi.plugins")

vimtex.lua

-- Assuming 'lazy.nvim' uses a table configuration similar to 'packer.nvim'
return {
  -- The plugin repository
  "lervag/vimtex",
  -- Conditions for lazy loading (this will depend on 'lazy.nvim' API)
  -- event = "BufRead *.tex",

  -- Plugin configuration function
  config = function()
    -- Automatically complete braces when typing LaTeX
    vim.g.vimtex_complete_close_braces = 1

    -- Set the compiler method for Vimtex to latexmk
    vim.g.vimtex_compiler_method = 'latexmk'

    -- there are warning messages and no error messages.
    -- Control whether or not to automatically open the |quickfix| window in case
    vim.g.vimtex_quickfix_open_on_warning = 0

    -- Choose which program to use to view PDF file
    vim.g.vimtex_view_method = 'skim'

    -- Value 1 allows forward search after every successful compilation
    vim.g.vimtex_view_skim_sync = 1

    -- Value 1 allows change focus to skim after command `:VimtexView` is given
    vim.g.vimtex_view_skim_activate = 1
  end,
}

deoplete.lua

return {
  'Shougo/deoplete.nvim',
  -- Define when to load the plugin, e.g., on certain command or event.
  -- event = "InsertEnter", -- or another appropriate event or command
  config = function()
    -- Enable Deoplete at startup
    vim.g["deoplete#enable_at_startup"] = 1

    -- Configure Deoplete for Vimtex
    vim.call("deoplete#custom#var", "omni", "input_patterns", {
      tex = vim.g["vimtex#re#deoplete"]
    })
  end,
}
0

1 Answer 1

1

I believe the main issue here is the use of the config key to lazy.nvim for configuring things. In particular, I suspect that you need to set deploete#enable_at_startup to 1 earlier than the config function is executed.

I think in general that you should consider to use the init key instead of the config key for the configuration that simply sets options. That is, only use the config key for things that are safe to postpone.

This, you should use something like this:

-- vimtex.lua
return {
  "lervag/vimtex",
  init = function()
    vim.g.vimtex_complete_close_braces = 1
    vim.g.vimtex_quickfix_open_on_warning = 0
    vim.g.vimtex_view_method = 'skim'
    vim.g.vimtex_view_skim_sync = 1
    vim.g.vimtex_view_skim_activate = 1
  end,
}

-- deoplete.lua
return {
  'Shougo/deoplete.nvim',
  init = function()
    vim.g["deoplete#enable_at_startup"] = 1
  end,
  config = function()
    vim.fn["deoplete#custom#var"]("omni", "input_patterns", {
      tex = vim.g["vimtex#re#deoplete"]
    })
  end,
}

Here the call to deplote#custom#var should not be done until after the plugin is loaded, so it can't go in the init block.

I removed your comments; feel free to add them back if you need them. I prefer to avoid comments, especially when you can simply do :help <c-r><c-w><cr> to get the full docs instead. I also removed some unnecessary code.

PS! Just to be clear, you should not lazy load VimTeX, so don't use any of the event, ft, keys, or cmd keys from the lazy specs!

2
  • Thanks a lot! I tried 2 days to make it work. You saved the week!
    – Mafsi
    Commented Nov 6, 2023 at 2:40
  • Glad to hear it :) Commented Nov 7, 2023 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.