forked from lervag/vimtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimtex.txt
5701 lines (4570 loc) · 237 KB
/
vimtex.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*vimtex.txt* A modern Vim/neovim filetype and syntax plugin for LaTeX files.
*VimTeX* *Vimtex* *vimtex*
Author: Karl Yngve Lervåg <karl.yngve@gmail.com>
License: MIT license {{{
Copyright (c) 2021 Karl Yngve Lervåg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
}}}
==============================================================================
CONTENTS *vimtex-contents*
Introduction |vimtex-introduction|
Comment on internal tex plugin |vimtex-comment-internal|
Feature overview |vimtex-features|
Requirements |vimtex-requirements|
Features provided by other plugins |vimtex-non-features|
Support for multi-file projects |vimtex-multi-file|
Support for TeX specifiers |vimtex-tex-directives|
Package detection |vimtex-package-detection|
Usage |vimtex-usage|
Default mappings |vimtex-default-mappings|
Options |vimtex-options|
Commands |vimtex-commands|
Map definitions |vimtex-mappings|
Insert mode mappings |vimtex-imaps|
Events |vimtex-events|
Text objects |vimtex-text-objects|
Completion |vimtex-completion|
Complete citations |vimtex-complete-cites|
Complete labels |vimtex-complete-labels|
Complete commands |vimtex-complete-commands|
Complete environments |vimtex-complete-environments|
Complete file names |vimtex-complete-filenames|
Complete glossary entries |vimtex-complete-glossary|
Complete packages |vimtex-complete-packages|
Complete documentclasses |vimtex-complete-classes|
Complete bibliographystyles |vimtex-complete-bibstyle|
Autocomplete |vimtex-complete-auto|
coc.nvim |vimtex-complete-coc.nvim|
deoplete |vimtex-complete-deoplete|
Neocomplete |vimtex-complete-neocomplete|
ncm2 |vimtex-complete-ncm2|
nvim-completion-manager |vimtex-complete-ncm|
YouCompleteMe |vimtex-complete-youcompleteme|
VimCompletesMe |vimtex-complete-vcm|
Folding |vimtex-folding|
Indentation |vimtex-indent|
Syntax highlighting |vimtex-syntax|
Syntax core specification |vimtex-syntax-core|
Syntax package specification |vimtex-syntax-packages|
Syntax conceal |vimtex-syntax-conceal|
Syntax group reference |vimtex-syntax-reference|
Navigation |vimtex-navigation|
Include expression (gf command) |vimtex-includeexpr|
Table of contents |vimtex-toc|
Custom mappings |vimtex-toc-custom-maps|
Denite/Unite source |vimtex-denite| / |vimtex-unite|
fzf.vim integration |vimtex-fzf|
Compilation |vimtex-compiler|
Latexmk |vimtex-latexmk|
Latexrun |vimtex-latexrun|
Tectonic |vimtex-tectonic|
Arara |vimtex-arara|
Generic |vimtex-compiler-generic|
Syntax Checking (Linting) |vimtex-lint|
Grammar Checking |vimtex-grammar|
textidote |vimtex-grammar-textidote|
vlty |vimtex-grammar-vlty|
View |vimtex-view|
Synctex |vimtex-synctex|
Forward search |vimtex-synctex-forward-search|
Backward search |vimtex-synctex-backward-search|
LaTeX Documentation |vimtex-latexdoc|
Context menu |vimtex-context-menu|
Citation context |vimtex-context-citation|
Code structure |vimtex-code|
API |vimtex-code-api|
FAQ |vimtex-faq|
Troubleshooting |vimtex-troubleshooting|
Credits |vimtex-credits|
Changelog |vimtex-changelog|
==============================================================================
INTRODUCTION *vimtex-introduction*
VimTeX provides convenient functionality for editing LaTeX documents. The
main goal of VimTeX is to be simple, functional, and to be easy to customize
and evolve.
The documentation is understandably too long for a full read through. It is
recommended that new users read or skim the entire introduction, as it should
give a clear idea of what VimTeX is and is not. The remaining part of the
documentation should then be considered a reference for the various parts of
the plugin.
------------------------------------------------------------------------------
COMMENT ON INTERNAL TEX PLUGIN *vimtex-comment-internal*
Vim ships with pretty decent LaTeX support out of the box. In particular, it
provides syntax highlighting (|ft-tex-syntax|), indentation (see the source
file $VIMRUNTIME/indent/tex.vim for the documentation), and some sensible
options (|ft-tex-plugin|).
*vimtex-tex-flavor*
When VimTeX is active, it will override the internal TeX plugin for the
filetype `tex` (|ft-tex-plugin|), both for syntax highlighting and for
filetype specific features. To prevent the unexpected behaviour where `.tex`
files by default will be recognized as the filetype `plaintex`
(|ft-plaintex-syntax|) for e.g. empty documents, VimTeX overrides the filetype
detection for `.tex`. The user may prevent this overriding by specifying the
|g:tex_flavor| option something different than `'latex'`.
-----------------------------------------------------------------------------
FEATURE OVERVIEW *vimtex-features*
- 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
- `MuPDF`
- `Zathura`
- `Okular`
- `qpdfview`
- `SumatraPDF`
- 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 content
- proper settings for |'include'|, |'includeexpr'|, |'suffixesadd'| and
|'define'|, which among other things
- allow |include-search| and |definition-search|
- give enhanced |gf| command
- Easy access to (online) documentation of packages
- Word count (through `texcount`)
- Motions
- 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
- `ic` `ac` Commands
- `id` `ad` Delimiters
- `ie` `ae` LaTeX environments
- `i$` `a$` Inline math structures
- `iP` `aP` Sections
- `im` `am` Items
- Other mappings
- 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 between e.g. `()` and `\left(\right)` with `tsd`/`tsD`
- Toggle (inline) fractions with `tsf`
- Close the current environment/delimiter in insert mode with `]]`
- 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>`
- Folding
- Indentation
- 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
- `import`
- `subfiles`
------------------------------------------------------------------------------
REQUIREMENTS *vimtex-requirements*
The following is a list of specific requirements for running VimTeX and some
of its key features. One may also be interested in reading |vimtex-faq-neovim|
and |vimtex-faq-windows|.
Vim version~
*vimtex_version_check*
VimTeX requires Vim version 8.0.1453 or neovim version 0.4.3. It will not
load for older versions, unless one adds >
let g:vimtex_version_check = 0
<
to one's `vimrc` file. This might work, but issues due to older versions
than the mentioned here will be ignored.
Vim configuration~
Some of the VimTeX scripts contain UTF-8 characters, and as such, it is
necessary to have the 'encoding' option set to utf8. This is not necessary
in neovim, only in Vim. Add the following to your vimrc file: >
set encoding=utf8
Compiler backend~
VimTeX uses `latexmk`, `latexrun`, `tectonic` or `arara` to compile the LaTeX document.
`latexmk`: http://users.phys.psu.edu/~collins/software/latexmk-jcc
"a perl script for running LaTeX the correct number of times to resolve
cross references, etc; it also runs auxiliary programs (bibtex, makeindex if
necessary, and dvips and/or a previewer as requested). It has a number of
other useful capabilities, for example to start a previewer and then run
latex whenever the source files are updated, so that the previewer gives an
up-to-date view of the document. The script runs on both UNIX and MS-WINDOWS
(XP, etc)." [Copied from the latexmk page.] (|vimtex-latexmk|)
`latexrun`: https://github.com/aclements/latexrun
Similar to `latexmk` in that it runs the desired LaTeX engine an
appropriate number of times, including `bibtex`/`biber`. However, it differs
in philosophy in that it only does the build part. It does not support
continuous builds, nor automatic starting of the viewer. However, it does
parse the output log in order to provide a more concise list of relevant
warnings and error messages (this has currently not been adapted to VimTeX,
as of yet). (|vimtex-latexrun|)
`tectonic`: https://tectonic-typesetting.github.io/
`tectonic` is a complete, self-contained TeX/LaTeX engine, powered by XeTeX
and TeXLive. It doesn't support continuous build like `latexmk` but it
presents other worth mentioning features such as automatic support file
downloading along with reproduceable builds and full Unicode and OpenType
fonts support thanks to the power of XeTeX. (|vimtex-tectonic|)
`arara`: https://github.com/cereda/arara
`arara` is a TeX automation tool similar to the above mentioned tools,
but where the compilation behaviour is typically defined in the preamble
of the document. (|vimtex-arara|)
Clientserver~
*vimtex-clientserver*
|+clientserver| is necessary for backward search from PDF viewer to Vim.
A server will be started automatically if Vim is running on Windows, or if
running in a GUI. If you use Vim under a terminal in Linux or macOS,
a server will not be started by default. Since Vim version 8.0.475, one can
use |remote_startserver()| to start a server from your `vimrc` file. The
following will ensure Vim starts with a server, if it is possible from
vimscript: >
if empty(v:servername) && exists('*remote_startserver')
call remote_startserver('VIM')
endif
<
Alternatively, Vim can be started with the command line option
`--servername`, e.g. `vim --servername VIM` . The simplest way to ensure
this is to add an alias to your `.bashrc` (or similar), that is, add: >
alias vim='vim --servername VIM'
<
For other methods of ensuring that Vim is started with a servername, see:
https://vim.fandom.com/wiki/Enable_servername_capability_in_vim/xterm
To test whether a server was successfully started, |serverlist()| can be
used. E.g. `:echo serverlist()`
Note: For |+clientserver| on neovim, see |vimtex-faq-neovim|.
------------------------------------------------------------------------------
FEATURES PROVIDED BY OTHER PLUGINS *vimtex-non-features*
The following is a list of features that one might think should be provided by
VimTeX, but that are instead better provided by other plugins.
* Linting and syntax checking |vimtex-nf-linting|
* Snippets/Templates |vimtex-nf-snippets|
* Tag navigation |vimtex-nf-tag-nav|
* Manipulate surrounding cmds/delims/envs |vimtex-nf-surround|
* Enhanced matching and higlighting of delimiters |vimtex-nf-enhanced-matchparen|
* Formatting |vimtex-nf-formatting|
* Filetype plugin for bib files |vimtex-nf-ftplugin-bib|
* Language server / texlab |vimtex-nf-lsp|
Linting and syntax checking~
*vimtex-nf-linting*
VimTeX has some support for linting through the |:compiler| command, see
|vimtex-lint|. There exists several more dedicated, automatic linting
plugins. The following plugins have support for (La)TeX syntax checking
through `lacheck` [0], `chktex` [1], and `proselint` [2].
`ale` https://github.com/dense-analysis/ale
`neomake` https://github.com/neomake/neomake
`syntastic` https://github.com/vim-syntastic/syntastic
`neomake` also supports `rubberinfo` [3]. One may also be interested in
`blacktex` [4], which may be used to clean up/fix LaTeX code.
[0]: https://www.ctan.org/pkg/lacheck
[1]: http://www.nongnu.org/chktex/
[2]: http://proselint.com/
[3]: https://www.systutorials.com/docs/linux/man/1-rubber-info/
[4]: https://github.com/nschloe/blacktex
Snippets/Templates~
*vimtex-nf-snippets*
Snippets and/or templates are provided by for instance `neosnippet` and
`UltiSnips`. See |vimtex-neosnippet| and |vimtex-UltiSnips| for more info.
Tag navigation~
*vimtex-nf-tag-nav*
One may navigate by tags with the |CTRL-]| mapping, e.g. from
`\eqref{eq:example}` to the corresponding `\label{eq:example}`. However,
this requires that a tag file has been generated with |ctags|. I recommend
that one uses the maintained version of ctags [0]. In addition,
I recommend that one uses a plugin that automatically generates the tag
files as necessary, e.g. |gutentags| [1].
See |vimtex-faq-tags| and |vimtex-faq-tags-bibtex| for concrete examples.
[0]: https://ctags.io/
[1]: https://github.com/ludovicchabant/vim-gutentags
Manipulate surrounding commands/delimiters/environments~
*vimtex-nf-surround*
VimTeX provides mappings that change, delete and toggle commands,
delimiters and environments (see the `ds`, `cs` and `ts` family of
mappings listed under |vimtex-default-mappings|). These mappings are
inspired by the great `surround.vim` [0] (|surround.txt|) by Tim Pope,
which provides mappings to manipulate surrounding delimiters such as `''`,
`""`, `()`, `[]`, `{}`, and `<>`. As such, the mappings from VimTeX
should work well together with, and as an extension of, `surround.vim`.
Consider also the customization described under |vimtex-faq-surround|.
The mappings may be repeated with the dot (|.|) command. See also
|g:vimtex_delim_list| if you are interested in customizing the delimiter
pairs that are recognized.
A different possibility is to use `vim-sandwich` [1] (|sandwich.txt|) by
Machakann, which may be considered a generalisation of `surround.vim` in
that it can handle much more complex sets of delimiters. `vim-sandwich`
is relatively easy to expand with custom surroundings and has built in
support for LaTeX-specific surroundings such as quotations, ```text''`,
and math delimiters, `$\left(a+b\right)$`. For a list of supported
delimiters, see |sandwich-filetype-recipes|. `vim-sandwich` supports
`vim-repeat` [2] in addition to `visualrepeat.vim` [3].
Note: The default mappings of `vim-sandwich` differ from those of
`surround.vim`, in that they use `s` as the prefix. E.g., to add
surroundings, one uses `sa{motion/textobject}{type-of-surrounding}`
instead of `ys{motion/textobject}{type-of-surrounding}`. If one prefers
the map variants from `surround.vim`, these are also available as an
option, see |sandwich-miscellaneous|. And it is also easy to define
custom mappings, if one prefers that.
Note: `vim-sandwich` actually consists of three plugins that work
together. One should make sure to read the docs for all of them:
|sandwich.txt|, |operator-sandwich.txt|, and |textobj-sandwich.txt|.
[0]: https://github.com/tpope/vim-surround
[1]: https://github.com/machakann/vim-sandwich
[2]: https://github.com/tpope/vim-repeat
[3]: http://www.vim.org/scripts/script.php?script_id=3848
Enhanced matching and highlighting of delimiters~
*vimtex-nf-enhanced-matchparen*
VimTeX highlights and allows navigation between matching pairs of
delimiters including those in math mode, such as `\bigl(` and `\bigr)`, and
the `\begin` and `\end` tags of environments. However, the implementation
may be slow (see also |vimtex-faq-slow-matchparen|, and so one may use
|g:vimtex_matchparen_enabled| to disable the highlighting).
Alternatively, one may use the plugin |match-up| [0], which offers enhanced
|matchparen| highlighting and `matchit.zip` style motions and |text-objects|
for a variety of file types. For LaTeX documents, it:
- Extends highlighting and the `%` motion to a number of middle
delimiters including
- `\bigm` and `\middle` marked delimiters
- `\item`s in `itemize` and `enumerate` environments
- `\toprule`, `\midrule`, `\bottomrule` in the `tabular` environment.
- `\if`, `\else` and `\endif`
Note: VimTeX does not support highlighting the middle delimiters.
- Adds motions, `g%`, `[%`, and `]%` and text objects, `a%` and `i%` which move
between matching delimiters and operate on delimited text.
For example, with match-up enabled, >
\left( \frac{a}{b} \middle| q \right)
<
the motion `%` will cycle through `\left(`, `\middle|`, and `\right)`, whereas
with VimTeX only `\left(` and `\right)` will be matched. The motion `g%`
will do the same, except in reverse.
To enable the plugin match-up after installation, add the following to
your vimrc: >
let g:matchup_override_vimtex = 1
<
Matching may become computationally intensive for complex LaTeX documents.
If you experience slowdowns while moving the cursor, the following option
is recommended to delay highlighting slightly while navigating: >
let g:matchup_matchparen_deferred = 1
<
Note: The exact set of delimiters recognized may differ between match-up
and VimTeX. For example, the mappings `da%` and `dad` will not in general
be identical, particularly if you have customized VimTeX's delimiters.
[0]: https://github.com/andymass/vim-matchup
Formatting~
*vimtex-nf-formatting*
VimTeX has a custom |formatexpr| that may be enabled with the option
|g:vimtex_format_enabled|. However, there are a lot of different styles for
formatting LaTeX manuscripts. These are typically much more relevant when
writing in collaboration with others. A good reference on this topic is [0],
and note in particular the box "Directives for using LaTeX with version
control systems".
The most basic style is to hard wrap lines at a given column, e.g. 80
columns, and this is exactly the type of formatting that is supported by
VimTeX. However, this is usually not very friendly when collaborating with
others, as it tends to mess up diffs between versions of the document.
Instead, one might want to consider one of these:
a) keeping each sentence on a line (use soft wrapping)
b) add additional indentation for split sentences [1]
c) use semantic line feeds [2]
In order to make it easier to use one of these styles of formatting, one may
want to use an external formatter:
- latexindent.pl [3]
- vim-bucky [4] (note: this is an alpha version as of October 2018)
Further, there are a range of Vim plugins that can be used to format your
document with external tools. Some of these also allow autoformatting of
some kind. In no particular order:
- neoformat [5]
- vim-codefmt [6]
- vim-autoformat [7]
- ale [8]
- vim-sentence-chopper [9]
[0]: https://en.wikibooks.org/wiki/LaTeX/Collaborative_Writing_of_LaTeX_Documents
[1]: http://dustycloud.org/blog/vcs-friendly-patchable-document-line-wrapping/
[2]: https://rhodesmill.org/brandon/2012/one-sentence-per-line/
[3]: https://github.com/cmhughes/latexindent.pl
[4]: https://github.com/dbmrq/vim-bucky
[5]: https://github.com/sbdchd/neoformat
[6]: https://github.com/google/vim-codefmt
[7]: https://github.com/Chiel92/vim-autoformat
[8]: https://github.com/dense-analysis/ale
[9]: https://github.com/Konfekt/vim-sentence-chopper
Filetype plugin for bib files~
*vimtex-nf-ftplugin-bib*
VimTeX is not a filetype plugin for bibliography (`.bib`) files. However,
it does include a couple of minor things, such as setting the 'comments' and
'commentstring' options and a simple indentation expression, see
|g:vimtex_indent_bib_enabled|.
Here are a couple of other related Vim plugins and external tools that might
be of interest:
- `bibtool`
An external tool for formatting, sorting, filtering, merging, and more of
`.bib` files.
http://www.gerd-neugebauer.de/software/TeX/BibTool/
- `tbibtools`
A set of ruby-based bibtex-related utilities for sorting, reformatting,
listing contents, and so on. Has optional Vim integration.
https://www.vim.org/scripts/script.php?script_id=1915
See also https://github.com/lervag/vimtex/issues/1293 for some related
discussions.
Language server / texlab~
*vimtex-nf-lsp*
In recent years, language servers (lsps) [0] has become very popular. There is
a language server for LaTeX and bibtex called texlab [1]. It may be
interesting both as an alternative to VimTeX and/or in addition. One may use
it with e.g. |vim-lsp| [2] or |coc-nvim| [3, 4] or other lsps.
See also this VimTeX issue [5] for more information.
[0]: https://langserver.org/
[1]: https://texlab.netlify.app/
[2]: https://github.com/prabirshrestha/vim-lsp
[3]: https://github.com/neoclide/coc.nvim
[4]: https://github.com/fannheyward/coc-texlab
[5]: https://github.com/lervag/vimtex/issues/1371
------------------------------------------------------------------------------
SUPPORT FOR MULTI-FILE PROJECTS *vimtex-multi-file*
VimTeX supports most multi-file documents. The main method uses a recursive
search algorithm that should find the main LaTeX file in most cases. For
special cases, there are several alternative methods for specifying the main
file. These alternative methods all require some explicit declaration of the
main file. Thus, these methods will be tried first, and the recursive search
is tried last if there are no explicit declarations that yield an appropriate
main LaTeX file candidate.
The methods are tried in the following order:
1. Buffer variable
2. TeX root directive
3. Subfiles package
4. File `.latexmain` specifier
5. Local `latexmkrc` file specifier (from `@default_files` option)
6. Recursive search
*b:vimtex_main*
Buffer variable~
The main file may be specified through the buffer variable `b:vimtex_main`.
To take effect, it has to be set prior to loading the buffer. If set after
the buffer is already loaded, |:VimtexReloadState| (by default bound to
|<localleader>lX|) can be used to make VimTeX aware of its new value.
If one uses project specific |vimrc| files, one may then use an |autocmd| to
specify the main file through this buffer variable with >
autocmd BufReadPre *.tex let b:vimtex_main = 'main.tex'
<
*vimtex-tex-root*
TeX root directive~
It is also possible to specify the main TeX file with a comment in one of
the first five lines of the current file. Some examples: >
%! TEX root = /path/to/my-main.tex
%! TEX root = ../*.tex
%! TEX root = **/main.tex
<
Note: It is allowed to use a globbing pattern (see |wildcards|). If there
are multiple matches, then VimTeX will ask for input when the buffer is
opened.
*vimtex-subfiles*
*vimtex-import*
Subfiles package~
VimTeX also supports the `import` [0] and the `subfiles` [1] packages that
can be used to make it easier to work with multi-file projects. If one uses
the `subfiles` package, the |:VimtexToggleMain| command is particularly
useful. Also note the option |g:vimtex_subfile_start_local|, which can be
used to automatically start in the local mode when opening a subfile
document.
With `subfiles`, included files will typically look like this: >
\documentclass[<main-path>]{subfiles}
\begin{document}
...
\end{document}
<
Here `<main-path>` is the path to the main file. It must be specified as
relative to the particular subfile. So, given the structure: >
main.tex
sub/sub.tex
<
The header in `sub.tex` should be `\documentclass[../main.tex]{subfiles}`.
Absolute paths like `/home/user/main.tex` are also allowed and should work
as expected.
[0]: https://www.ctan.org/pkg/import
[1]: https://www.ctan.org/pkg/subfiles
File .latexmain specifier~
In some cases, it might be preferable to specify the main file by creating
an indicator file. The indicator file should be an empty file, and the name
must be the name of the desired main file with `.latexmain` appended. An
example should make this clear: >
path/file.tex
path/file.tex.latexmain
path/sections/file1.tex
path/sections/file2.tex
<
Here `path/file.tex.latexmain` indicates for `file1.tex` and `file2.tex`
that `path/file.tex` is the main LaTeX file.
Local latexmkrc file specifier~
It is possible to specify to latexmk which files to compile with the
`@default_files` option in the `latexmkrc` configuration file. VimTeX
supports reading this option in any LOCAL `latexmkrc` or `.latexmkrc` file.
Note: `@default_files` is a list of files, VimTeX will use the first
entry that is found.
Recursive search~
If no other method provides an appropriate candidate, then the recursive
search detects the main LaTeX file by searching for a file in the current
and parent directories that includes the present file and has the
`\documentclass` line.
This should work in most cases, but it may fail if for instance the project
structure is something like this: >
path1/main.tex
path2/chapter.tex
<
That is, the main file detection will not work for the file `chapter.tex`,
because the main file does not live in the same folder or a parent folder.
In this particular case, the TeX root directive should work.
Note: In rare cases, such as if there are _very_ many tex files in the
directory tree, this method may be slow. One may therefore disable it
through the option |g:vimtex_disable_recursive_main_file_detection|.
------------------------------------------------------------------------------
SUPPORT FOR TEX DIRECTIVES *vimtex-tex-directives*
VimTeX supports two of the commonly used TeX directives [0]: the TeX root and
the TeX program directive. The TeX root directive was already described above,
see |vimtex-tex-root|.
*vimtex-tex-program*
The TeX program directive works by specifying the TeX compiler program in
a comment in one of the first lines of the main project file. It is parsed
during initialization, but if desired one may manually reload VimTeX in order
to reset the program during an editing session. See |:VimtexReload| and
|<plug>(vimtex-reload)| (by default mapped to `<localleader>lx`).
The syntax is best explained with an example: >
%! TEX program = program
Here `program` corresponds to a key in the |g:vimtex_compiler_latexmk_engines|
or |g:vimtex_compiler_latexrun_engines| dictionaries. See also [0,1].
[0]: https://tex.stackexchange.com/q/78101/34697
[1]: https://github.com/lervag/vimtex/issues/713
------------------------------------------------------------------------------
PACKAGE DETECTION *vimtex-package-detection*
VimTeX maintains a list of latex packages that are required by the current
project. This list is used by VimTeX for instance to determine which commands
to suggest during command completion (see |vimtex-complete-commands|) and
which packages to look up documentation for (see |vimtex-doc-package|). The
list can be viewed with |:VimtexInfo|.
The package list is determined in two ways: >
1. If a `.fls` file exists having the name of the main file, it is scanned.
This file is created by `latex` (or `pdflatex`, `xelatex`, ...) if it is
run with the `-recorder` option. This is enabled by default with `latexmk`.
Parsing the `.fls` file is done both at VimTeX initialization and after
each successful compilation, if possible.
Note: Parsing after successful compilations requires that one uses
a) continuous compilation with callbacks (see the `callback` option
for |g:vimtex_compiler_latexmk|), or
b) single-shot compilation.
2. Otherwise, the preamble is parsed for `\usepackage` statements. This is
slower and less accurate than `.fls` file parsing. Therefore, it is only
done during VimTeX initialization. If desired, one may manually reload
VimTeX to parse the preamble again during an editing session. See
|:VimtexReload| and |<plug>(vimtex-reload)| (by default mapped to
`<localleader>lx`).
==============================================================================
USAGE *vimtex-usage*
Default mappings |vimtex-default-mappings|
Options |vimtex-options|
Commands |vimtex-commands|
Map definitions |vimtex-mappings|
Insert mode mappings |vimtex-imaps|
Events |vimtex-events|
------------------------------------------------------------------------------
DEFAULT MAPPINGS *vimtex-default-mappings*
VimTeX is designed to be controlled by a selection of mappings. Note,
though, that most of the mappings are also available as commands, see
|vimtex-commands|.
Many of the mappings utilize the |maplocalleader|. The right-hand sides are
provided as <plug>-mappings, see |using-<plug>|. For any given <plug> map, the
default mapping will only be created if it does not already exist. This means
that if a user defines a custom mapping, e.g. with >
nmap <space>li <plug>(vimtex-info)
then the corresponding default left-hand side will not be mapped.
If one prefers, one may disable all the default mappings through the option
|g:vimtex_mappings_enabled|. Custom mappings for all desired features must
then be defined through the listed RHS <plug>-maps or by mapping the available
commands.
In the below list of mappings, LHS is the default mapping, RHS is the
corresponding <plug>-maps, and MODE indicates in which vim mode the mappings
are valid. See |map-modes| for an explanation of the various modes. The
indicator refers to the prefix of the corresponding map command, e.g. `n`
refers to an |nmap|, `nx` refers to both |nmap| and |xmap|, and so on.
In addition to the mappings listed below, VimTeX provides convenient insert
mode mappings to make it easier and faster to type mathematical equations.
This feature is explained in more detail later, see |vimtex-imaps|.
---------------------------------------------------------------------~
LHS RHS MODE~
---------------------------------------------------------------------~
<localleader>li |<plug>(vimtex-info)| `n`
<localleader>lI |<plug>(vimtex-info-full)| `n`
<localleader>lt |<plug>(vimtex-toc-open)| `n`
<localleader>lT |<plug>(vimtex-toc-toggle)| `n`
<localleader>lq |<plug>(vimtex-log)| `n`
<localleader>lv |<plug>(vimtex-view)| `n`
<localleader>lr |<plug>(vimtex-reverse-search)| `n`
<localleader>ll |<plug>(vimtex-compile)| `n`
<localleader>lL |<plug>(vimtex-compile-selected)| `nx`
<localleader>lk |<plug>(vimtex-stop)| `n`
<localleader>lK |<plug>(vimtex-stop-all)| `n`
<localleader>le |<plug>(vimtex-errors)| `n`
<localleader>lo |<plug>(vimtex-compile-output)| `n`
<localleader>lg |<plug>(vimtex-status)| `n`
<localleader>lG |<plug>(vimtex-status-all)| `n`
<localleader>lc |<plug>(vimtex-clean)| `n`
<localleader>lC |<plug>(vimtex-clean-full)| `n`
<localleader>lm |<plug>(vimtex-imaps-list)| `n`
<localleader>lx |<plug>(vimtex-reload)| `n`
<localleader>lX |<plug>(vimtex-reload-state)| `n`
<localleader>ls |<plug>(vimtex-toggle-main)| `n`
<localleader>la |<plug>(vimtex-context-menu)| `n`
dse |<plug>(vimtex-env-delete)| `n`
dsc |<plug>(vimtex-cmd-delete)| `n`
ds$ |<plug>(vimtex-env-delete-math)| `n`
dsd |<plug>(vimtex-delim-delete)| `n`
cse |<plug>(vimtex-env-change)| `n`
csc |<plug>(vimtex-cmd-change)| `n`
cs$ |<plug>(vimtex-env-change-math)| `n`
csd |<plug>(vimtex-delim-change-math)| `n`
tsf |<plug>(vimtex-cmd-toggle-frac)| `nx`
tsc |<plug>(vimtex-cmd-toggle-star)| `n`
tse |<plug>(vimtex-env-toggle-star)| `n`
tsd |<plug>(vimtex-delim-toggle-modifier)| `nx`
tsD |<plug>(vimtex-delim-toggle-modifier-reverse)| `nx`
<F7> |<plug>(vimtex-cmd-create)| `nxi`
]] |<plug>(vimtex-delim-close)| `i`
ac |<plug>(vimtex-ac)| `xo`
ic |<plug>(vimtex-ic)| `xo`
ad |<plug>(vimtex-ad)| `xo`
id |<plug>(vimtex-id)| `xo`
ae |<plug>(vimtex-ae)| `xo`
ie |<plug>(vimtex-ie)| `xo`
a$ |<plug>(vimtex-a$)| `xo`
i$ |<plug>(vimtex-i$)| `xo`
aP |<plug>(vimtex-aP)| `xo`
iP |<plug>(vimtex-iP)| `xo`
am |<plug>(vimtex-am)| `xo`
im |<plug>(vimtex-im)| `xo`
% |<plug>(vimtex-%)| `nxo`
]] |<plug>(vimtex-]])| `nxo`
][ |<plug>(vimtex-][)| `nxo`
[] |<plug>(vimtex-[])| `nxo`
[[ |<plug>(vimtex-[[)| `nxo`
]m |<plug>(vimtex-]m)| `nxo`
]M |<plug>(vimtex-]M)| `nxo`
[m |<plug>(vimtex-[m)| `nxo`
[M |<plug>(vimtex-[M)| `nxo`
]n |<plug>(vimtex-]n)| `nxo`
]N |<plug>(vimtex-]N)| `nxo`
[n |<plug>(vimtex-[n)| `nxo`
[N |<plug>(vimtex-[N)| `nxo`
]r |<plug>(vimtex-]r)| `nxo`
]R |<plug>(vimtex-]R)| `nxo`
[r |<plug>(vimtex-[r)| `nxo`
[R |<plug>(vimtex-[R)| `nxo`
]/ |<plug>(vimtex-]/| `nxo`
]* |<plug>(vimtex-]star| `nxo`
[/ |<plug>(vimtex-[/| `nxo`
[* |<plug>(vimtex-[star| `nxo`
K |<plug>(vimtex-doc-package)| `n`
---------------------------------------------------------------------~
------------------------------------------------------------------------------
OPTIONS *vimtex-options*
*g:vimtex_enabled*
Set to 0 to disable VimTeX.
Default value: Undefined.
*g:vimtex_cache_root*
Specify the cache directory for VimTeX.
Default value:
`'$XDG_CACHE_HOME/vimtex'` if `$XDG_CACHE_HOME` is defined
`'~/.cache/vimtex'` otherwise
*g:vimtex_cache_persistent*
Specify whether to use persistant caching.
Default value: 1
*g:vimtex_compiler_enabled*
Use this option to disable/enable the `compiler` interface, see |vimtex-compiler|.
Default value: 1
*g:vimtex_compiler_progname*
Path to vim executable used for the callback functionality. It must be set
correctly in order for the callback function to work. The default value
should work correctly in most cases, but in some cases, e.g. for MacVim, one
might need to set it manually to get the callbacks to work as expected.
Default value on Vim: |v:progpath| or |v:progname|
Default value on neovim: `nvr` if available, else same as Vim
See also: |vimtex-faq-neovim|
*g:vimtex_compiler_method*
Set the compiler method. Available choices are:
latexmk~
See |vimtex-latexmk| for more details, and |g:vimtex_compiler_latexmk|
for customization.
latexrun~
See |vimtex-latexrun| for more details, and |g:vimtex_compiler_latexrun|
for customization.
tectonic~
See |vimtex-tectonic| for more details, and |g:vimtex_compiler_tectonic|
for customization.
arara~
See |vimtex-arara| for more details, and |g:vimtex_compiler_arara| for
customization.
generic~
See |vimtex-compiler-generic| for more details, and
|g:vimtex_compiler_generic| for customization.
Default value: 'latexmk'
*g:vimtex_compiler_latexmk*
This is a dictionary that allows customization of the |vimtex-latexmk|
compiler. The values set by the user will take precedence over the default
values.
Default value: >
let g:vimtex_compiler_latexmk = {
\ 'build_dir' : '',
\ 'callback' : 1,
\ 'continuous' : 1,
\ 'executable' : 'latexmk',
\ 'hooks' : [],
\ 'options' : [
\ '-verbose',
\ '-file-line-error',
\ '-synctex=1',
\ '-interaction=nonstopmode',
\ ],
\}
<
The default value shows which entries may be changed. Here the different
keys are explained in more detail:
build_dir~
This option sets the compilation build directory. It corresponds to the
`-output-directory` option in `latexmk`. If the path is a relative path,
then it will be considered relative to the main project file.
Note 1: This option only works with `latexmk` version 4.27 and later.
Note 2: If `$out_dir` is added to `.latexmkrc`, then the `.latexmkrc` setting
will have priority.
Note 3: If |$VIMTEX_OUTPUT_DIRECTORY| is defined, it will have the highest
priority.
callback~
If enabled, this option tells `latexmk` to run |vimtex#compiler#callback|
after compilation is finished.
Note: When using |clientserver|, the callback is run with the vim
executable defined by |g:vimtex_compiler_progname|.
continuous~
If enabled, `latexmk` will run in continuous mode, i.e. with the `-pvc`
argument. This means that the document is compiled automatically by
`latexmk` every time a related file has been changed, until the processes
is stopped.
If disabled, `latexmk` will run single shot compilations.
Note: The events |VimtexEventCompileStarted| and |VimtexEventCompileStopped|
are only relevant when this option is enabled.
executable~
The name/path to the `latexmk` executable.
hooks~
A list of |Funcref|s. If running in continuous mode, each hook will be
called for each line of output from `latexmk`, with that line as argument.
E.g., to show information about the compilation run numbers, one could do
this: >
function! Callback(msg)
let l:m = matchlist(a:msg, '\vRun number (\d+) of rule ''(.*)''')
if !empty(l:m)
echomsg l:m[2] . ' (' . l:m[1] . ')'
endif
endfunction
let g:vimtex_compiler_latexmk = { 'hooks': [function('Callback')] }
<
options~
This is a list of options that are passed to `latexmk`. The default
options should work well for most people.
Note: Options like `-pdf` or `-lualatex` should NOT be added to this list.
These are options used to specify the LaTeX processor/engine, see
instead |g:vimtex_compiler_latexmk_engines|.
Note: Options may also be specified indirectly to `latexmk` through both
a global and a project specific `.latexmkrc` file. One should know,
though, that options specified on the command line has priority, and
so if one wants to override one of the above default options, then
one has to set this key to a list that contains the desired options.
*g:vimtex_compiler_latexmk_engines*
Defines a map between TeX program directive (|vimtex-tex-program|) and
compiler engine. This is used by |vimtex-latexmk| to define the LaTeX
program. The `_` key defines the default engine.
Note: If the TeX program directive is not specified within the main project
file, and if `$pdf_mode` is added to a project-specific `.latexmkrc`
file, then the compiler engine will be deduced from the value of
`$pdf_mode`. The supported values of `$pdf_mode` are 0 (pdflatex), 4
(lualatex) and 5 (xelatex). See the latexmk documentation for details.
Default value: >
let g:vimtex_compiler_latexmk_engines = {
\ '_' : '-pdf',
\ 'pdflatex' : '-pdf',
\ 'dvipdfex' : '-pdfdvi',
\ 'lualatex' : '-lualatex',
\ 'xelatex' : '-xelatex',
\ 'context (pdftex)' : '-pdf -pdflatex=texexec',
\ 'context (luatex)' : '-pdf -pdflatex=context',
\ 'context (xetex)' : '-pdf -pdflatex=''texexec --xtx''',
\}
*g:vimtex_compiler_latexrun*
This is a dictionary that allows customization of the |vimtex-latexrun|
compiler. The values set by the user will take precedense over the default
values.
Default value: >
let g:vimtex_compiler_latexrun = {
\ 'build_dir' : '',
\ 'options' : [
\ '-verbose-cmds',
\ '--latex-args="-synctex=1"',
\ ],
\}
<
The default value shows which entries may be changed. Here the different
keys are explained in more detail:
build_dir~
Same as |g:vimtex_compiler_latexmk| / `build_dir`.
options~
This is a list of options that are passed to `latexrun`. The default
options should work well for most people.
Note: By default, the option `-pdf` is also supplied to indicate the LaTeX
engine. This may be changed on a per project basis with TeX
directives, see |vimtex-tex-program| or the two compiler-specific
options
|g:vimtex_compiler_latexmk_engines|
and |g:vimtex_compiler_latexrun_engines|.
The latter two options may also be used to change the default engine.
*g:vimtex_compiler_latexrun_engines*