I'm really new to Vim, and trying to proceed as described here: https://vim.fandom.com/wiki/Keep_your_vimrc_file_clean for language specific customization.

I'm trying to implement automatic line breaks in LaTeX. So far my .vimrc file has only one line:

filetype plugin indent on

I've also created a file located at ~/.vim/ftplugin/tex.vim that reads

setlocal textwidth=80
setlocal number

However when I try to load some .tex file these changes do not take effect. I tried :scriptnames to see what vim is loading and the output is the following

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/syntax/syntax.vim
  4: /usr/share/vim/vim74/syntax/synload.vim
  5: /usr/share/vim/vim74/syntax/syncolor.vim
  6: /usr/share/vim/vim74/filetype.vim
  7: ~/.vimrc
  8: /usr/share/vim/vim74/ftplugin.vim
  9: /usr/share/vim/vim74/indent.vim
 10: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
 11: /usr/share/vim/vim74/plugin/gzip.vim
 12: /usr/share/vim/vim74/plugin/logiPat.vim
 13: /usr/share/vim/vim74/plugin/matchparen.vim
 14: /usr/share/vim/vim74/plugin/netrwPlugin.vim
 15: /usr/share/vim/vim74/plugin/rrhelper.vim
 16: /usr/share/vim/vim74/plugin/spellfile.vim
 17: /usr/share/vim/vim74/plugin/tarPlugin.vim
 18: /usr/share/vim/vim74/plugin/tohtml.vim
 19: /usr/share/vim/vim74/plugin/vimballPlugin.vim
 20: /usr/share/vim/vim74/plugin/zipPlugin.vim
 21: /usr/share/vim/vim74/syntax/vim.vim
 22: /usr/share/vim/vim74/syntax/python.vim
 23: /usr/share/vim/vim74/ftplugin/vim.vim
 24: /usr/share/vim/vim74/indent/vim.vim

Thanks in advance for your help


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
        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.