vim-latex与vimtex如何选择
作为一个理科生,终生都离不开数学公式。而LaTeX绝对是处理数学公式的王者,在编辑LaTeX中的众多工具中,使用vim或neovim配合编辑LaTeX的插件又是王者中的王者。在众多的插件中,vim-latex和vimtex是网络上提到最多的,也是使用者最多的插件,但是这两者该如何选择呢?经过本人的实践,最终选择了vim-latex.
选择依据分析
众多网络文章都提到了插件vimtex, 按其官方介绍:VimTeX is a modern Vim and Neovim filetype and syntax plugin for LaTeX files. , 或许就是这个modern让许多人选择了它。诚然vimtex是一个优秀的插件,我们来看一下它提供的功能(引用其README.md):
- Document compilation with [latexmk](https://www.cantab.net/users/johncollins/latexmk/index.html), [latexrun](https://github.com/aclements/latexrun), [tectonic](https://tectonic-typesetting.github.io), or [arara](https://github.com/cereda/arara) - LaTeX log parsing for quickfix entries using - internal method - [pplatex](https://github.com/stefanhepp/pplatex) - Compilation of selected part of document - Support for several PDF viewers with forward search - [MuPDF](http://www.mupdf.com/) - [Okular](https://okular.kde.org/) - [qpdfview](https://launchpad.net/qpdfview) - [Skim](http://skim-app.sourceforge.net/) - [SumatraPDF](http://www.sumatrapdfreader.org/free-pdf-reader.html) - [TeXShop](https://pages.uoregon.edu/koch/texshop/) - [Zathura](https://pwmt.org/projects/zathura/) - Other viewers are supported through a general interface - Completion of - citations - labels - commands - file names for figures, input/include, includepdf, includestandalone - glossary entries - package and documentclass names based on available `.sty` and `.cls` files - Document navigation through - table of contents - table of labels - proper settings for `'include'`, `'includexpr'`, `'suffixesadd'` and `'define'`, which among other things - allow `:h include-search` and `:h definition-search` - give enhanced `gf` command - Easy access to (online) documentation of packages - Word count (through `texcount`) - Motions ([link to GIF demonstrations](VISUALS.md#motion-commands)) - Move between section boundaries with `[[`, `[]`, `][`, and `]]` - Move between environment boundaries with `[m`, `[M`, `]m`, and `]M` - Move between math environment boundaries with `[n`, `[N`, `]n`, and `]N` - Move between frame environment boundaries with `[r`, `[R`, `]r`, and `]R` - Move between comment boundaries with `[*` and `]*` - Move between matching delimiters with `%` - Text objects ([link to GIF demonstrations](VISUALS.md#text-objects)) - `ic ac` Commands - `id ad` Delimiters - `ie ae` LaTeX environments - `i$ a$` Math environments - `iP aP` Sections - `im am` Items - Other mappings ([link to GIF demonstrations](VISUALS.md#deleting-surrounding-latex-content)) - Delete the surrounding command, environment or delimiter with `dsc`/`dse`/`ds$`/`dsd` - Change the surrounding command, environment or delimiter with `csc`/`cse`/`cs$`/`csd` - Toggle starred command or environment with `tsc`/`tse` - Toggle inline and displaymath with `ts$` - Toggle between e.g. `()` and `\left(\right)` with `tsd` - Toggle (inline) fractions with `tsf` - Close the current environment/delimiter in insert mode with `]]` - Add `\left ... \right)` modifiers to surrounding delimiters with `
而插件vim-latex(又称latex-suite), 按vimtex的README.md
The main difference between VimTeX and LaTeX-Suite (aka vim-latex) is probably that VimTeX does not try to implement a full fledged IDE for LaTeX inside Vim. E.g.:
- VimTeX does not provide a full snippet feature, because this is better handled by UltiSnips or neosnippet or similar snippet engines.
- VimTeX builds upon Vim principles: It provides text objects for environments, inline math, it provides motions for sections and paragraphs
- VimTeX uses latexmk, latexrun, tectonic or arara for compilation with a callback feature to get instant feedback on compilation errors
- VimTeX is very modular: if you don’t like a feature, you can turn it off.
vimtex提供的较好的特性是光标在各环境中移动,这点是vim-latex不具备的功能。但是vim或neovim的特性,使用搜索功能或数字键加hjkl方式移动光标,好像vimtex也没有占据足够的优势。
vimtex方便的更改环境功能,例如cse可以方便的更换为新的环境,但是vim-latex也可以使用<S-F5>快捷键快速更换环境,再则考虑到编写环境前作者肯定是规划好的环境,所以更改环境是一个低概率事件。此处注意,Neovim中同时按下组键<S+F5>(也就是Shift+F5)返回的是F17,并不能获得vim-latex所需的组合键<S-F5>!! 具体请参考
keycode in terminal for vim&neovim
, 于是做出修改:
修改完毕,在neovim中可以正常使用环境或命令的替换。很多人选择vimtex的一个重要原因是其可以配置增量编译,实现时时查看结果,但是LaTeX的精神本身就是!对于一个熟悉LaTeX的人来讲随时关注结果并不是必须的,除非公式比较复杂,而这只需要编译一下看看结果即可。时时编译的代价就是电脑消耗更多的资源,对于我的笔记本来说,风扇一直转发出的噪音会干扰我的写作思维。对于一个初入LaTeX的人,这或许是一个较好的选择,但是对于一个足够熟悉LaTeX的人来讲,不是必须的,也是符合Linux思维。
综上所述,vim-latex和vimtex都是优秀的LaTeX插件,但是前者提供了完备的功能,后者的优势功能是一些低频率使用的功能,综合平衡的话还是选择vim-latex更好一些。由于二者并不冲突,所以可以同时配置二个插件,获取各自的功能这是一个比较折中的方案,但是不太符合Linux纯净化的哲学思想,所以我还是选择了前者,在没有足够的理由前应该不会同时安装二者。
作为可用的配置,下面将二者的配置文件列出,方便大家参考:
{% tabs neovim配置latex %}
| |
| |
{% endtabs %}