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, latexrun, tectonic, or arara
- LaTeX log parsing for quickfix entries using
- internal method
- pplatex
- Compilation of selected part of document
- Support for several PDF viewers with forward search
- Completion of
- citations
- labels
- commands
- file names for figures, input/include, includepdf, includestandalone
- glossary entries
- package and documentclass names based on available
.styand.clsfiles
- Document navigation through
- table of contents
- table of labels
- proper settings for
'include','includexpr','suffixesadd'and'define', which among other things- allow
:h include-searchand:h definition-search - give enhanced
gfcommand
- allow
- Easy access to (online) documentation of packages
- Word count (through
texcount) - Motions (link to GIF
demonstrations)
- 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
%
- Move between section boundaries with
- Text objects (link to GIF
demonstrations)
ic acCommandsid adDelimitersie aeLaTeX environmentsi$ a$Math environmentsiP aPSectionsim amItems
- Other mappings (link to GIF
demonstrations)
- 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)withtsd - Toggle (inline) fractions with
tsf - Close the current environment/delimiter in insert mode with
]] - Add
\left ... \right)modifiers to surrounding delimiters with<F8> - Insert new command with
<F7> - Convenient insert mode mappings for faster typing of e.g. maths
- Context menu on citations (e.g.
\cite{...}) mapped to<cr>
- Delete the surrounding command, environment or delimiter with
- Improved folding (
:h 'foldexpr') - Improved indentation (
:h 'indentexpr') - Syntax highlighting
- A consistent core syntax specification
- General syntax highlighting for several popular LaTeX packages
- Nested syntax highlighting for several popular LaTeX packages
- Highlight matching delimiters
- Support for multi-file project packages
而插件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.
这两个插件有相同的部分,比如说输入希腊字母,vim-latex在任何模式下都可以输出对应的希腊字母命令,而vimtex在数学模式中才输出希腊字母,相较而言vimtex更加保险一些,但是对于一个熟悉LaTeX的人来讲,这个事情都是知道的,影响不大,只能说vimtex更加细致一点。而vim-latex提供了完整的LaTeX的输入语法,同时提供了<++>标记方法,可以使用Ctrl+j快速的移动光标,这点是vimtex所无法比拟的。按vimtex的说法,vimtex把补全的任务交给了其他插件,但是就专业性和速度上讲,vim-latex绝对领先。
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, 于是做出修改:
1 | map <F17> <S-F5> |
修改完毕,在neovim中可以正常使用环境或命令的替换。很多人选择vimtex的一个重要原因是其可以配置增量编译,实现时时查看结果,但是LaTeX的精神本身就是!对于一个熟悉LaTeX的人来讲随时关注结果并不是必须的,除非公式比较复杂,而这只需要编译一下看看结果即可。时时编译的代价就是电脑消耗更多的资源,对于我的笔记本来说,风扇一直转发出的噪音会干扰我的写作思维。对于一个初入LaTeX的人,这或许是一个较好的选择,但是对于一个足够熟悉LaTeX的人来讲,不是必须的,也是符合Linux思维。
综上所述,vim-latex和vimtex都是优秀的LaTeX插件,但是前者提供了完备的功能,后者的优势功能是一些低频率使用的功能,综合平衡的话还是选择vim-latex更好一些。由于二者并不冲突,所以可以同时配置二个插件,获取各自的功能这是一个比较折中的方案,但是不太符合Linux纯净化的哲学思想,所以我还是选择了前者,在没有足够的理由前应该不会同时安装二者。
作为可用的配置,下面将二者的配置文件列出,方便大家参考:
1 | #! /usr/bin/env lua |
1 | #! /usr/bin/env lua |