When I open a new instance of vim without any 'filename' argument and write some LaTeX code, I cannot just compile it to pdf with latexmk, because it needs a file to compile from. However, even after writing the new buffer to a .tex file, latexmk still tells me "no file name specified" and it won't compile. This happens with vim and gvim on Debian, but it doesn't happen with gvim on Windows.

After writing the new file with :w <filename>, I tried running :e <filename> or :argadd <filename> or :badd <filename>, but I got the same error. In order to compile to pdf successfully I have to quit and run vim again with the 'filename' argument, or open a new instance of vim without any argument and then run :e <filename> (notice that running a new instance, then creating for the first time with :w <filename> and then running :e <filename>, did NOT work).

Can you help me understand how Vimtex or latexmk work in this case?

1 Answer 1


I can reproduce your issue with the following sequence:

  1. Open Vim or neovim without any arguments.

  2. Specify the filetype to load VimTeX: :set ft=tex.

  3. Insert some simple, compileable LaTeX content in the empty buffer.

  4. Write the buffer to a file, e.g. :write test.tex.

  5. Compile with \ll. We can now observe the issue raised in the question.

The problem is that VimTeX initialization occurs before the buffer is related to any files in your system. You can inspect this by looking at the VimTeX state content with :VimtexInfo or \li.

You can make things work by forcing VimTeX to reload/reinitialize with :VimtexReload or \lx.

  • 1
    You guessed exactly the steps to reproduce the issue, sorry for not being more precise. Thanks so much for your answer. Mar 21, 2021 at 21:27
  • 1
    Happy to hear it helps. Mar 21, 2021 at 21:41

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.