forked from lervag/vimtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimtex.txt
7076 lines (5688 loc) · 291 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|
Support for multi-file projects |vimtex-multi-file|
Support for TeX specifiers |vimtex-tex-directives|
Package detection |vimtex-package-detection|
Integration with other plugins |vimtex-and-friends|
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|
nvim-cmp |vimtex-complete-nvim-cmp|
nvim-compe |vimtex-complete-nvim-compe|
MUcomplete |vimtex-complete-mucomplete|
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-compiler-latexmk|
Latexrun |vimtex-compiler-latexrun|
Tectonic |vimtex-compiler-tectonic|
Arara |vimtex-compiler-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|
Viewer configuration |vimtex-view-configuration|
Evince |vimtex-view-evince|
MuPDF |vimtex-view-mupdf|
Okular |vimtex-view-okular|
qpdfview |vimtex-view-qpdfview|
Sioyek |vimtex-view-sioyek|
Skim |vimtex-view-skim|
SumatraPDF |vimtex-view-sumatrapdf|
TeXShop |vimtex-view-texshop|
Zathura |vimtex-view-zathura|
Zathura (simple) |vimtex-view-zathura-simple|
Synctex |vimtex-synctex|
Forward search |vimtex-synctex-forward-search|
Inverse search |vimtex-synctex-inverse-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 contents
- 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 *vimtex-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$` Math environments
- `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 inline and displaymath with `ts$`
- Toggle between e.g. `()` and `\left(\right)` with `tsd`/`tsD`
- 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>`
- 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. Windows users should also read |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 >vim
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 ~
VimTeX requires |:filetype-plugin-on| and optionally |:filetype-indent-on|.
There are several features in VimTeX that depend on the syntax parsing used
for syntax highlighting. Examples include functions like
|vimtex#syntax#in_mathzone| and text objects like |<plug>(vimtex-i$)|. This
is important to be aware of especially for neovim users who are interested
in Tree-sitter. If you use Tree-sitter for syntax highlighting and thus
disable the normal Vim syntax feature, then you will also lose the VimTeX
features that depend on the built-in syntax parser. For more info, see
|vimtex-faq-treesitter|.
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: >vim
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 (e.g. bibtex). 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-compiler-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-compiler-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 reproducible builds and full Unicode and OpenType
fonts support thanks to the power of XeTeX. (|vimtex-compiler-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-compiler-arara|)
Clientserver ~
*vimtex-clientserver*
Vim requires |+clientserver| in order to allow inverse search from the PDF
viewer to Vim (see |vimtex-synctex-inverse-search|). The clientserver is
used by VimTeX. Thus, if one uses Vim one must ensure that it starts
a server. Neovim does not have this requirement.
A server will be started automatically if Vim is running on Windows or if it
is running in a GUI (gVim). If you use Vim under a terminal in Linux or
MacOS, a server will not be started by default. Also, MacVim users should be
aware of some differences from regular Vim and should therefore read
|macvim-clientserver| carefully.
Since Vim version 8.0.475, one can use |remote_startserver()| to start
a server from your `vimrc` file. The following vimrc configuration snippet
will ensure that Vim starts with a server, if possible: >vim
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: >bash
alias vim='vim --servername VIM'
<
One can use |serverlist()| to check whether a server was successfully
started, e.g. with `:echo serverlist()`.
Neovim does not implement the same clientserver feature. Instead, it
implements the MessagePack-RPC protocol (see |RPC|). VimTeX relies on this
protocol in the same fashion as the clientserver. Both Vim and neovim have
the |v:servername| variable that contains the name/location of the server
with which we need to communicate.
------------------------------------------------------------------------------
SUPPORT FOR MULTI-FILE PROJECTS *vimtex-multi-file*
VimTeX supports most multi-file documents and has several methods to locate
the `main` document. Locating this file is very important, because the main
file is the one that must be compiled.
The default method for locating the main file uses a directory-scan algorithm
that searches for a main LaTeX file, see method 6 below. It is expected to
work in the vast majority of cases.
There are several alternative methods for specifying the main file that can be
more flexible and are relevant for certain work flows and use cases. These
methods all require some explicit declaration of the main file and are
therefore tried prior to the directory scan.
The complete list of methods in the order of priority is as follows and are
then described in more detail:
1. Buffer variable
2. TeX root directive
3. Subfiles package
4. File `.latexmain` specifier
5. Local `latexmkrc` file specifier (from `@default_files` option)
6. Directory scan
*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.
A convenient way to use this feature is to add an |BufReadPre| |autocmd| in
one's |vimrc|. An example is warranted: >vim
augroup VimTeX
autocmd!
autocmd BufReadPre /path/to/project/*.tex
\ let b:vimtex_main = '/path/to/project/main.tex'
augroup END
<
Note: When writing such rules, one should be aware that the `*` is not the
same as regular globbing because it also includes directory
separators. Also, one should use `/` on every OS. See |file-pattern|
for more info on the |autocmd| file pattern syntax.
Note: Users may be interested in the concept of project specific vim
configuration. This is supported in Vim, see 'exrc' and 'secure'.
There are also several plugins to help work with project specific
settings, such as:
* https://github.com/embear/vim-localvimrc
* https://github.com/tpope/vim-projectionist
* https://github.com/jenterkin/vim-autosource
* https://github.com/ii14/exrc.vim
* https://github.com/MarcWeber/vim-addon-local-vimrc/
* https://github.com/MunifTanjim/exrc.nvim (neovim only)
* See also:
https://superuser.com/questions/598947/setting-vim-options-only-for-files-in-a-certain-directory-tree/598970#598970
*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. This is often referred to as a TeX
directive, see |vimtex-tex-directives| for more info. The syntax is best
described by some examples: >latex
%! TEX root = /path/to/my-main.tex
% ! TeX root = ../*.tex
%!Tex Root=**/main.tex
%! TeX root: ../main.tex
<
As can be seen, the words "tex root" are recognized regardless of casing and
the spaces are ignored. Also, both a colon and an equal sign can be used.
VimTeX parses this directive during initialization. Thus, users should be
aware that they need to reload (with |:VimtexReload|) or restart Vim/neovim
if they change the TeX root directive.
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: >latex
\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.
Directory scan ~
If the above methods don't give an appropriate candidate for a main file of
the present file, then a search for a suitable main file from the current
directory and upwards is started.
A candidate `.tex` file qualifies as a main file if the following three
requirements are all satisfied:
1. It includes the present file, either directly or indirectly.
2. The expanded content contains a `\documentclass` line near the top.
3. The expanded content contains `\begin{document}`.
Notice that the main file itself does not need to contain the
`\documentclass` line and `\begin{docment}`, since these can stem from
included `.tex` files. The option |g:vimtex_include_indicators| is used by
the parser to specify commands that include `.tex` files for the recursive
expansion.
In cases where automatic detection of the main file through the directory
scan fails, one may explicitly set up method 1 to 5 instead. The
|vimtex-tex-root| is usually a good alternative.
Note: Recursive directory descents are not performed to find the main file.
That is, if the current file is `./B/chapter.tex` then `./A/main.tex`
will not be found as the main file, because the descent to
subdirectory `./A/` is not performed.
------------------------------------------------------------------------------
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
only when it is required by a compiler backend.
The syntax is best explained with an example: >latex
%! TeX program = lualatex
%! TEX TS-program = xelatex
The left-hand side must contain the text "tex program" or "tex ts-program" and
as with |vimtex-tex-root|, the words are recognized regardless of casing and
the spaces are ignored. The right-hand side must correspond 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 (which is set by default when using
latexmk, unless overridden in an initialization file). 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`).
------------------------------------------------------------------------------
INTEGRATION WITH OTHER PLUGINS *vimtex-and-friends*
VimTeX provides a lot of convenient and useful features for working with LaTeX
files. However, there are several features that one might expect to be part of
VimTeX, but that are left out because they are better served by other plugins.
Let's call them "friends".
The following is an overview of some such features. We also try to give hints
and suggestions for how to best integrate with VimTeX experience, if that is
applicable.
* Linting and syntax checking |vimtex-af-linting|
* Snippets/Templates |vimtex-af-snippets|
* Tag navigation |vimtex-af-tag-nav|
* Manipulate surrounding cmds/delims/envs |vimtex-af-surround|
* Enhanced matching and highlighting of delimiters |vimtex-af-enhanced-matchparen|
* Formatting |vimtex-af-formatting|
* Filetype plugin for bib files |vimtex-af-ftplugin-bib|
* Language servers (texlab & ltex) |vimtex-af-lsp|
Linting and syntax checking ~
*vimtex-af-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-af-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-af-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-af-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 and math
delimiters. 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-af-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, >latex
\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: >vim
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: >vim
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-af-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)
- semantic-linebreaker [5] (note: this is a web-based tool)
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 [6]
- vim-codefmt [7]
- vim-autoformat [8]
- ale [9]
- vim-sentence-chopper [10]
[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/waldyrious/semantic-linebreaker
[6]: https://github.com/sbdchd/neoformat
[7]: https://github.com/google/vim-codefmt
[8]: https://github.com/Chiel92/vim-autoformat
[9]: https://github.com/dense-analysis/ale
[10]: https://github.com/Konfekt/vim-sentence-chopper
Filetype plugin for bib files ~
*vimtex-af-ftplugin-bib*
VimTeX is not a full filetype plugin for bibliography files (`.bib`). However,
it does alter the 'comments' and 'commentstring' options and provide basic
indentation and folding; see |g:vimtex_indent_bib_enabled| and
|g:vimtex_fold_bib_enabled|, respectively.
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/
- `GooseBib`
Some simple command-line tools to clean-up / modify BibTeX files.
https://github.com/tdegeus/GooseBib
- `bibtex-tidy`
Another tool for formatting and cleaning `.bib` files.
https://flamingtempura.github.io/bibtex-tidy/
- `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 servers ~
*vimtex-af-lsp*
In recent years, language servers (LSPs) [0] have 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 an addition.
There is currently no known conflict between texlab and VimTeX, although
there is some feature overlap. E.g., both texlab and VimTeX provides
advanced completion in various contexts. As texlab is written in Rust and
runs in a separate thread, it is no surprise that it will have a clear
performance advantage. However, VimTeX does use caches to speed up
completion which should in most cases work well.
To use texlab, one must use an LSP client, e.g. |vim-lsp| [2], neovim's
built-in LSP client [3], or |coc-nvim| [4, 5]. See also this VimTeX issue
[6] for more information.
In addition to texlab, there is also a dedicated grammar and spell checking
language server called LTeX [7]. It relies on LanguageTool and supports both
LaTeX and other markup languages. It may be a useful tool to use in
conjunction with VimTeX as an alternative to |vimtex-grammar|.
[0]: https://langserver.org/
[1]: https://github.com/latex-lsp/texlab
[2]: https://github.com/prabirshrestha/vim-lsp
[3]: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#texlab
[4]: https://github.com/neoclide/coc.nvim
[5]: https://github.com/fannheyward/coc-texlab
[6]: https://github.com/lervag/vimtex/issues/1371
[7]: https://valentjn.github.io/ltex/index.html
==============================================================================
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 use `<localleader>l` as a common prefix, where the
default |<localleader>| is `\`. Thus, `<localleader>ll` will for most people
mean `\ll`. The prefix may be changed with |g:vimtex_mappings_prefix|.
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 >vim
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`
ts$ |<plug>(vimtex-env-toggle-math)| `n`
<F6> |<plug>(vimtex-env-surround-line)| `n`
|<plug>(vimtex-env-surround-operator)| `n`
<F6> |<plug>(vimtex-env-surround-visual)| `x`
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`
<F8> |<plug>(vimtex-delim-add-modifiers)| `n`
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 persistent 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_silent*
Set this to 1 or |v:true| to silence the compiler messages during start,
stop, and callbacks.
Default: 0
*g:vimtex_compiler_method*
This option sets the compiler method. There are two ways to configure this
option:
i) Explicity as a string.
ii) Dynamically through a function.
In the first variant, you can choose from the following list of compiler
methods:
Value Documentation Configuration ~
`latexmk` |vimtex-compiler-latexmk| |g:vimtex_compiler_latexmk|
`latexrun` |vimtex-compiler-latexrun| |g:vimtex_compiler_latexrun|
`tectonic` |vimtex-compiler-tectonic| |g:vimtex_compiler_tectonic|
`arara` |vimtex-compiler-arara| |g:vimtex_compiler_arara|
`generic` |vimtex-compiler-generic| |g:vimtex_compiler_generic|
In the second variant, the option must be specified as the name of
a function or a |Funcref|. Using a |Funcref| is only possible with Lua in
Neovim. The function is passed the path to the main TeX file as a single
string argument and must return the desired method as a string. The method
must be one from the above list of available methods.
Using a function allows a lot of flexibility in the choice of compiler
method. For instance, one could use `arara` for files that have `arara`
specifications at the top and fall back to `latexmk` for other files: >vim
function! SetCompilerMethod(mainfile)
if filereadable(a:mainfile)
for line in readfile(a:mainfile, '', 5)
if line =~# '^%\s*arara'
return 'arara'
endif
endfor
endif
return 'latexmk'
endfunction
let g:vimtex_compiler_method = 'SetCompilerMethod'
<
Default value: `'latexmk'`
*g:vimtex_compiler_clean_paths*
A list of additional path expressions for generated files that you want to
be cleaned by `:VimtexClean`. Note that this is NOT relevant for the
compiler backends |vimtex-compiler-latexmk| and |vimtex-compiler-latexrun|.
These backends provide their own clean implementations.
Each expression is a glob expression (see |glob()| and |wildcards|) and each
path is assumed rooted to the project root. For instance, to clean any
generated `_minted` paths (including directories), you could use something
like this: >vim