1

I'm learning to use Vim with vim-latex and I'm wondering when does the plugin actually activates once I open a file.

My intuition tells me that any file with the .tex extension should do it, but if I open a new file in the terminal with

vim test.tex

The empty file is open but the plugin is not activated. Furthermore, if I save, quit and reopen, it is still not activated.

I've noticed it kicks in when I write the \begin{document} ... \end{document} environments and then I save, quit and reopen.

Is this normal behavior? My purpose is to be able to open a new file and then immediately load a .tex template using vim-latex.

  • That answer is related, but doesn't explains the behavior I'm experiencing. As described, the plugin should kick in immediately only by file extension, which is not happening. Maybe it is a particular issue of vim-latex? Albeit, when writing :scriptnames, the vim-latex files are not loaded. – pancho Apr 21 at 0:28
  • I'm not familiar with vim-tex, but i'm sure that tex filetype plugin has kicked in for your empty test.tex, it's name is tex_latexSuite.vim – dedowsdi Apr 21 at 1:14
  • Just to iterate what @dedowsdi said, Vim has two filetype plugins for tex files. One is plaintex and the other is tex. The latter is more desirable for Latex files but Vim won't know if the file is Latex or PlainTex if you have no content in the file. That's why the plugin, which depends on the filetype autocommand of Tex filetype, is triggered after the file is recognized as a Latex document. So, to answer your question, the behavior is completely normal, even though I have no idea why there is a plaintex filetype and who uses that. – klaus Apr 21 at 3:27
  • 1
    You can try to use :autocmd FileType plaintex set ft=tex. But report back here what happens cause you would need some fine tuning to use that as a long term solution. – klaus Apr 21 at 4:14
2

Vim has two filetype plugins for tex files. One is plaintex and the other is tex. The latter is more desirable for Latex files but Vim won't know if the file is Latex or PlainTex if you have no content in the file. That's why the plugin, which depends on the filetype autocommand of Tex filetype, is triggered after the file is recognized as a Latex document. So, to answer your question, the behavior is completely normal, even though I have no idea why there is a plaintex filetype and who uses that.

The solutions below are suggested better to worse, i.e. the first solution is best, the second better and the third meh:

  • You can put the following in your vimrc to always use tex as the default filetype:

    let g:tex_flavor = 'latex'
    
  • You can put the following in your ~/.vim/after/ftplugin/plaintex.vim file:

    set filetype=tex
    
  • You can put the following autocmds in your vimrc in order to set the filetype to tex from plaintex:

    augroup filetype_tex
        au!
        autocmd FileType plaintex set filetype=tex
    augroup END
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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