lervag / vimtex

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

lazyvim: vimtex mappings no longer appear #2799

Closed albertfgu closed 1 year ago

albertfgu commented 1 year ago

Description

I configured my vimtex settings around June, updating everything to the current version of LazyVim at the time. After updating all packages some things seem to have changed and I can't quite figure it out, perhaps you have some idea. The main thing that's obviously wrong is that my local leader commands no longer show up. This is my lazy.nvim config:

return {
  {
    "lervag/vimtex",
    -- Lervag recommends putting configuration here:
    -- https://github.com/lervag/vimtex/issues/2698
    -- https://github.com/lervag/vimtex/issues/2699
    init = function()
      ------ Viewer ------
      vim.g.vimtex_view_method = "skim"
      -- Set this option to 1 to highlight current line in PDF after command
      vim.g.vimtex_view_skim_reading_bar = 0
      -- Perform a forward search after successful compilation
      -- vim.g.vimtex_view_skim_sync = 1
      -- Make Skim have focus after command |:VimtexView|
      -- vim.g.vimtex_view_skim_activate = 1
      -- Don't automatically open PDF viewer after first compilation
      -- vim.g.vimtex_view_automatic = 0

      vim.g.vimtex_imaps_leader = ";"

      -- g:vimtex_parser_bib_backend -- Default backend for parsing bibliographies
      -- g:vimtex_complete_bib -- This option is a dictionary for controlling the citation completion.
      -- g:vimtex_complete_ref -- This option is a dictionary for controlling the label completion.

      -- g:vimtex_delim_toggle_mod_list Defines a list of delimiter modifiers to toggle (e.g. add \big)
      vim.g.vimtex_delim_stopline = 200 -- A tolerance for the number of lines to search for matching delimiters in each direction.
      vim.g.vimtex_echo_verbose_input = 1 -- For 'sr' mappings

      ------ Compilation ------
      vim.g.vimtex_compiler_latexmk = {
        options = {
          '-verbose',
          '-file-line-error',
          '-synctex=1',
          '-interaction=nonstopmode',
          '-shell-escape',
        }
      }

      ------ Folding ------
      -- See :h vimtex-folding
      vim.g.vimtex_fold_enabled = 1
      -- g:vimtex_fold_manual

      -- g:vimtex_indent_on_ampersands -- By default, VimTeX will align on `leading` ampersands e.g. in math aligned environments or in tabular environments.

      ------ Subfiles
      vim.g.vimtex_subfile_start_local = 0

      ------ Quickfix ------
      -- g:vimtex_quickfix_method # TODO: look up pplatex
      -- g:vimtex_quickfix_open_on_warning = 1

      vim.g.vimtex_quickfix_ignore_filters = {
        'Overfull',
        'Underfull',
      }
      -- vim.g.vimtex_quickfix_ignore_filters = [
      --             \ 'Overfull',
      --             \ 'Underfull',
      --             \ 'Reference',
      --             \ 'undefined references',
      --             \ 'Font shape',
      --             \]
      --             -- \ 'Marginpar on page',
      --             -- \ 'overfull',
      --             -- \ 'underfull',
      --             -- \ 'package',
      --             -- \ 'reference',

      ------ Syntax ------
      vim.g.vimtex_syntax_nospell_comments = 0

      ------ Completion ------
      -- g:vimtex_complete_bib
      -- g:vimtex_complete_close_braces
      -- g:vimtex_complete_enabled
      -- g:vimtex_complete_ignore_case
      -- g:vimtex_complete_ref
      -- g:vimtex_complete_smart_case

      ------ Events ------
      -- Compile on initialization, cleanup on quit
      -- augroup vimtex_event_1
      --   au!
      --   au User VimtexEventQuit     VimtexClean
      --   -- au User VimtexEventInitPost VimtexCompile
      -- augroup END
      vim.api.nvim_create_augroup("vimtex_clean", { clear = true })
      vim.api.nvim_create_autocmd("User", {
        group = "vimtex_clean",
        pattern = "VimtexEventQuit",
        command = "VimtexClean",
      })
      -- See `:h vimtex-events` for more ideas, e.g.
      -- -- Specify extra behaviour after reverse goto
      -- augroup vimtex_event_4
      --   au!
      --   au User VimtexEventViewReverse normal! zMzvzz
      -- augroup END

      -- TODO: Port to Lua
      vim.cmd([[
        function! s:TexFocusVim() abort
        execute "!open -a iTerm"
        " Use silent to suppress "Press ENTER or type command to continue" messages
        " silent execute "!open -a iTerm"
        redraw!
        endfunction

        augroup vimtex_event_focus
        au!
        au User VimtexEventViewReverse call s:TexFocusVim()
        augroup END
      ]])
    end,
  },
  -- Disable treesitter in vimtex (:h vimtex-faq-treesitter)
  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ignore_install = { "latex" },
    },
  },
}

Steps to reproduce

Not looking for detailed reproduction at the moment, just if @lervag immediately knows what is wrong. If not I'll spend more effort in trying to reproduce the issue.

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: macOS 13.3.1 (22E261)
  Vim version: NVIM v0.9.0
  Has clientserver: true
  Servername: /var/folders/mc/hmdq_0hd7vbfkrp6mgvjmd480000gn/T/nvim.albertgu/t0BmxN/nvim.4514.0

VimTeX project: main
  base: main.tex
  root: /Users/albertgu/mamba-paper
  tex: /Users/albertgu/mamba-paper/main.tex
  main parser: current file verified
  document class: article
  packages: algorithm algorithmicx algpseudocode amsbsy amsfonts amsgen amsmath amsopn amstext amsthm array atbegshi atbegshi-ltx atveryend atveryend-ltx authblk auxhook bbm biblatex bigintcalc bitset blx-case-expl3 bm booktabs calc caption caption3 cleveref color comment diagbox enumitem epstopdf-base etoolbox expl3 float gettitlestring graphics graphicx hycolor hyperref iclr2024_conference iftex ifthen import infwarerr intcalc keyval kvdefinekeys kvoptions kvsetkeys letltxmacro logreq ltxcmds mathalpha mathtools mhsetup microtype multirow nameref nicefrac pdfescape pdftexcmds pict2e pifont refcount rerunfilecheck savetrees subcaption subfiles times titlesec trig uniquecounter url wrapfig xcolor xkeyval xparse
  source files:
    main.tex
    src/abstract.tex
    src/intro.tex
    src/background.tex
    src/method.tex
    src/conclusion.tex
    src/discussion.tex
    src/related.tex
    src/appendix.tex
    src/synthetic.tex
    src/dna.tex
    src/ablations.tex
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
      -shell-escape
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 33
      output: /var/folders/mc/hmdq_0hd7vbfkrp6mgvjmd480000gn/T/nvim.albertgu/t0BmxN/0
      cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode -shell-escape -pdf 'main.tex'
      pid: 0
  viewer: Skim
  qf method: LaTeX logfile
lervag commented 1 year ago

This is my lazy.nvim config:

Here's a cleaned up version where I've removed comments and removed options that you did not need to set. I've also tried to convert the Vimscript autocommand for you.

return {
  {
    "lervag/vimtex",
    init = function()
      vim.g.vimtex_view_method = "skim"
      vim.g.vimtex_imaps_leader = ";"
      vim.g.vimtex_delim_stopline = 200
      vim.g.vimtex_compiler_latexmk = {
        options = {
          '-verbose',
          '-file-line-error',
          '-synctex=1',
          '-interaction=nonstopmode',
          '-shell-escape',
        }
      }
      vim.g.vimtex_fold_enabled = 1
      vim.g.vimtex_quickfix_ignore_filters = {
        'Overfull',
        'Underfull',
      }

      vim.api.nvim_create_augroup("vimtex", { clear = true })
      vim.api.nvim_create_autocmd("User", {
        group = "vimtex",
        pattern = "VimtexEventQuit",
        command = "VimtexClean",
      })
      vim.api.nvim_create_autocmd("User", {
        group = "vimtex",
        pattern = "VimtexEventViewReverse",
        callback = function()
          vim.system({"open", "-a", "iTerm"})
        end,
      })
    end,
  },
}

Notice, you should ensure that VimTeX is not lazy loaded; i.e., if you asked lazy.nvim to lazy load stuff by default (this is not the default behaviour, so if you do this it is because you configured lazy that way), then you need to add lazy = false.

I configured my vimtex settings around June, updating everything to the current version of LazyVim at the time. After updating all packages some things seem to have changed and I can't quite figure it out, perhaps you have some idea. The main thing that's obviously wrong is that my local leader commands no longer show up.

The config looks good to me.

Can you explain slightly more verbosely what you mean? Do you mean that things like \ll no longer works for starting the compiler?

albertfgu commented 1 year ago

Thanks for the response and lua-fying the autocommand!

I figured out the issue, which your response also helped me realize: the localleader of the config I was using changed: https://github.com/LazyVim/LazyVim/commit/258f339bcf8197ece54d66bf6ed6f351cb6e98cb

I just had to set it back. (I prefer starting everything with the same leader key so I have my localleader mapped to space as well)

lervag commented 1 year ago

Glad to hear you figured things out! :)