lervag / vimtex

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

Loading after vim-polyglot prevents loading of vimtex at all #1822

Closed sanjayankur31 closed 4 years ago

sanjayankur31 commented 4 years ago

Issue If vimtex is loaded after vim-polyglot, it will not load at all.

This isn't a bug in vimtex, but I guess it needs to be noted somewhere that vimtex should be loaded before vim-polyglot. I'll be happy to file a bug against vim-polyglot if that would be preferred too.

minimal.vim

vimtex does not load:

set nocompatible
call plug#begin('~/.vim/plugged')

filetype off
Plug 'sheerun/vim-polyglot'
Plug 'lervag/vimtex'
call plug#end()

let g:tex_flavor='latex'

vimtex will load correctly:

set nocompatible
call plug#begin('~/.vim/plugged')

filetype off
Plug 'lervag/vimtex'
Plug 'sheerun/vim-polyglot'
call plug#end()

let g:tex_flavor='latex'

minimal.tex

  \documentclass{minimal}
  \begin{document}
  Hello world!
  \end{document}

Commands/Input If vim-polyglot is listed/loaded before, vimtex commands are not available in vim at all. One cannot even run :VimtexInfo

Observed Behaviour It looks like loading of vim-polyglot first prevents loading of vimtex (see the attached files).

Expected Behaviour vimtex should load correctly

Output from VimtexInfo NA

doesn-not-work-scriptnames.txt works-scriptnames.txt

Other information:

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 29 2020 00:00:00)
Included patches: 1-1770
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
+balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
+browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              +perl/dyn          +title
+clientserver      +job               +persistent_undo   +toolbar
+clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3/dyn       +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       +lua/dyn           +ruby/dyn          +wildmenu
+dialog_con_gui    +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       +X11
+dnd               +mouse             +sound             -xfontset
-ebcdic            +mouseshape        +spell             +xim
+emacs_tags        +mouse_dec         +startuptime       +xpm
+eval              +mouse_gpm         +statusline        +xsmp_interact
+ex_extra          -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim82"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/at-spi-2.0 -pthread    -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld   -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0  -lSM -lICE -lXpm -lXt -lX11 -lSM -lICE  -lm  -lselinux  -lncurses -lcanberra  -lacl -lattr -lgpm -ldl   -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc
lervag commented 4 years ago

Have you updated your plugins recently? As far as I've understood, vim-polyglot should not do anything for LaTeX, and so this should not be a problem.

sanjayankur31 commented 4 years ago

Yes, I ran a vim -c PlugUpdate recently. Both vimtex and polyglot are at the current commits:

I had the same impression about polyglot. I read in some issues here that vim-polyglot no longer supplies tex files and so should not interfere with vimtex, but this is what i found. Perhaps it's a bug in polyglot then---it still loads the default tex file provided by vim somehow which then interferes with vimtex?

lervag commented 4 years ago

Perhaps it's a bug in polyglot then---it still loads the default tex file provided by vim somehow which then interferes with vimtex?

Yes, this has to be a bug with polyglot. Notice in particular #1790 and @sheerun's comment. Perhaps @sheerun could comment on this?

sheerun commented 4 years ago

I've described problem and possible solution at https://github.com/sheerun/vim-polyglot/issues/580

In short autoload files are loaded in the order they are defined in .vimrc, that is vim-polyglot tex.vim autoload files are loaded before (or rather instead of) vimtex's tex.vim files. The solution is to reverse order in .vimrc to:

Plug 'sheerun/vim-polyglot'
Plug 'lervag/vimtex'

but best solution would be for vimtex to switch from tex filetype to vimtex filetype (i.e. create ftdetect/vimtex.vim file that does au BufNewFile,BufRead *.bbl,*.dtx,*.latex,*.ltx,*.sty set ft=vimtex, and then rename all tex.vim files to vimtex.vim files.

sheerun commented 4 years ago

this would also solve issues with vim8 packages that you describe in the readme

sanjayankur31 commented 4 years ago

Plug 'sheerun/vim-polyglot' Plug 'lervag/vimtex'

Just a note: this should be the other way around. I.e., vim-polyglot should be loaded last.

lervag commented 4 years ago

but best solution would be for vimtex to switch from tex filetype to vimtex filetype (i.e. create ftdetect/vimtex.vim file that does au BufNewFile,BufRead *.bbl,*.dtx,*.latex,*.ltx,*.sty set ft=vimtex, and then rename all tex.vim files to vimtex.vim files.

No! I don't agree. The best solution would be for vim-polyglot to stop adding tex.vim scripts!

People should learn to understand what they are doing. If people use vim-polyglot, they are adding a huge amount of filetype specific scripts that may or may not conflict with other plugins. In this particular case, it obviously conflicts with vimtex. Vimtex implements a filetype plugin (and hopefully in near future syntax plugin) for LaTeX files, and there should be no reason to not override the tex filetype. The plugin clash is not caused by vimtex, but by vim-polyglot. So, back to where I started: if people combine vim-polyglot with vimtex, they should understand what they are doing. The problem is not caused by vimtex, and so I will make no change to vimtex for this issue.

sheerun commented 4 years ago

tex.vim scripts are in vim upstream as well

sanjayankur31 commented 4 years ago

Yes, but they don't create trouble for vimtex from the looks of it. At least that's what my MWE indicates.

lervag commented 4 years ago

tex.vim scripts are in vim upstream as well

That's not relevant. Vim provides a set of runtime scripts by default. These are essentially just bundled scripts and plugins, including syntax scripts and filetype plugins. The entire point of plugin managers such as vim-plug is to update the runtimepath such that installed plugins are prioritized ahead of the intrinsic bundled plugins. Specifically, the first paths in &runtimepath are prioritized, so e.g. vim-plug will insert the plugin directories at the beginning of the runtimepath. The after directories are correspondingly placed at the end.

As far as I can understand, vim-polyglot aims to be sort of an improved runtime that i) adds support for a lot more filetypes and ii) improves the support for some filetypes. This means that it should be loaded so as to not disturb other more specific filetype plugins such as vimtex. IMHO, it is up to vim-polyglot to instruct its users how to properly install the plugin so that it does not interfere with other plugins. In particular, vim-polyglot should not be put early in the runtimepath. With vim-plug, it should be the last (or one of the last) plugins to be loaded.

Again, IMHO, the problem is not with vimtex. The solution is not to change vimtex.

sheerun commented 4 years ago

Vim recommends for plugins to not be dependent on loading order: https://github.com/vim/vim/issues/7056

Actually vim-polyglot depends very much to be put first in runtime path: https://github.com/sheerun/vim-polyglot/issues/571

I understand at this point I can't change your mind, but the same way I could say your plugin conflicts with mine. Until I figure out how to hack this, the workaround is as described above (change order of vimtex and vim-polyglot).

sheerun commented 4 years ago

(depends very much to be put first in runtime path == it was the case, now it's just more performant if loaded first)

sheerun commented 4 years ago

by the way in the readme you write "Please note that by default Vim puts custom /start/ plugin directories at the end of the &runtimepath. This means the built in filetype plugin is loaded, which prevents Vimtex from loading. See #1413 for two suggested solutions to this. To see which scripts are loaded and in which order, use :scriptnames.". It's very the same "issue", but without vim-polyglot. I don't believe I should remove tex.vim from polyglot.

lervag commented 4 years ago

I understand at this point I can't change your mind, but the same way I could say your plugin conflicts with mine. Until I figure out how to hack this, the workaround is as described above (change order of vimtex and vim-polyglot).

Yes, I understand that you may have the opposite view from me here. And of course, I don't mean to be rude to you in any way.

by the way in the readme you write "Please note that by default Vim puts custom /start/ plugin directories at the end of the &runtimepath. This means the built in filetype plugin is loaded, which prevents Vimtex from loading. See #1413 for two suggested solutions to this. To see which scripts are loaded and in which order, use :scriptnames.". It's very the same "issue", but without vim-polyglot. I don't believe I should remove tex.vim from polyglot.

Yes, you are right. I think this quote from the README file may be irrelevant now, though, cf. @clason's comment in #1413.

I don't really care so much what you do with vim-polyglot, since I'm not using it myself, but I am curious what is the difference between the content of tex.vim in vim-polyglot from the versions provided by Vims runtime?

sheerun commented 4 years ago

it is the same if you're using the most recent vim. it is only useful if you must use old vim, but you'd like the newest syntax highlighting

sheerun commented 4 years ago

(but in the future I could decide to replace it with something better)