TeX-7
This is my toned-down fork from Elias Toivanen’s TeX-9 Vim plugin for writing LaTeX documents. [Source code]
I liked TeX-9 a lot (it’s efficient and minimalistic), but there were some itches that after some time, became itchy enough for me to finally scratch them. The result is TeX-7, a filetype plugin that, just like TeX-9, aims to enhance the writing experience of high quality documents with LaTeX and Vim. The goal of TeX-7 is to be simple and “Vimish,” meaning that the focus is on carefully thought-out key mappings and features that are already present in a typical Vim installation. If you need to write a thesis or research articles and insist on having only one editor for all editing tasks, then TeX-7 is for you!
Unlike TeX-9 (which used Python bindings), TeX-7 is written in pure Vimscript. It has a couple of sweet features, e.g., smarter completion, and distraction-free background save-and-compile: just hit <Esc>:ww<Enter>
, and it’s done. Feedback will only be shown in case of error. Here are some of the other main features of TeX-7:
- Powerful text-object for LaTeX environments;
- Omni-completion of BibTeX database entries and label references;
- Omni-completion of mathematical symbols, and included files;
- Preview of BibTeX database entries and label references;
- Preview of
\includegraphics
(supported formats: JPG, PNG, or PDF); - Filetype specific indentation (courtesy of Johannes Tanzler);
- No-hassle settings, relatively few mappings;
TeX-9 also came with its own LaTeX templates (skeletons for documents). I prefer to use my own, so TeX-7 does not provide this feature.
Shoutouts & thanks. To Elias Toivanen, the original author of the TeX-9 plugin, from which I forked TeX-7.
Below is the plugin’s documentation. If you are completely new to TeX-7, start by glancing the Overview section. If it sounds like TeX-7 might be for you, then go back to Installation and work your way from there!
1. Installation
To install TeX-7, I will assume you are a good citizen, and use something like Tim Pope’s Pathogen plugin, or something to that effect. In the case of Pathogen, just clone this plugin into the bundle directory, usually ~/.vim/bundle
, and run :Helptags
afterwords.
Next, open up vimrc
and ensure it contains the following line:
filetype plugin indent on
Strictly speaking, for basic usage you don’t need to configure anything else. However, you may find the following settings very useful in making TeX-7 more convenient to use. (Below Boolean means either 0 or 1, the former meaning false, and latter, true).
compiler_cmd
: Array of Strings- Command used to compile LaTeX sources (see example below).
- Default: empty.
compiler_cmd_double
: Array of Strings- Command to do two compilations in a row.
- Default: empty (but see Compilation).
disable
: Boolean- TeX-7 is disabled temporarily.
- Default: 0 (TeX-7 is loaded).
diamond_tex
: Boolean- TeX-9 originally mapped
<LocalLeader><
to\leq
, and<LocalLeader>>
to\geq
. However, I find these LaTeX commands actually easy to type, to I prefer to map<LocalLeader><
to\langle\rangle,
and<LocalLeader>>
to<>
(sometimes called diamond). Among other things, the latter is useful when writing Beamer templates. - Default: 1 (map
<LocalLeader>>
to<>
and<LocalLeader><
to\(lr)angle)
.
- TeX-9 originally mapped
kerning_cmd
: String- For the
SwapQuotesPunctuation()
function. See below. - Optional.
- Default: empty.
- For the
leader
: String- Most TeX-7 mappings begin with this prefix.
- Optional.
- Default:
,
viewer
: String- Application used for viewing PDF files.
- Optional.
- Default: empty.
viewer_images
: String- Application used for viewing JPG/PNG files.
- Optional.
- Default: empty.
You set these, er, settings, by defining a Dictionary
called g:tex_seven_config
in your vimrc
(or better yet, in $VIMRUNTIME/ftplugin/tex.vim
). In this latter file, you can add any settings that are not overrides of things defined by TeX-7. (For such overrides, use the after/
directory; cf. below).
Example:
let g:tex_seven_config = {
\ 'compiler_cmd' : [ "/bin/bash," "CompileTeX.sh" ],
\ 'viewer' : 'okular' , \ 'viewer_images' : 'gwenview' }
Important note #1: \label
retrieval requires the perl-json
module (in addition to Perl itself, of course).1
Important note #2: Do NOT set this Dictionary
in $VIMRUNTIME/after/ftplugin/tex.vim
. This file is only sourced after TeX-7 has ran, and thus if you set, say, a custom LocalLeader
, all of the mappings that TeX-7 sets, will use the previous value of LocalLeader
, instead of the one you just set!
Important note #3: If you put any custom settings in either $VIMRUNTIME/ftplugin/tex.vim
or $VIMRUNTIME/after/ftplugin/tex.vim
, then you are highly encouraged to ensure that neither of them are sourced more than once. One way is to defined a sort of “include guards,” like these:
" Put this at the start of $VIMRUNTIME/ftplugin/tex.vim.
if exists('b:ftplugin_tex_init')
finish
endif let b:ftplugin_tex_init = 1
" Put this at the start of $VIMRUNTIME/after/ftplugin/tex.vim.
if exists('b:after_ftplugin_tex_init')
finish
endif let b:after_ftplugin_tex_init = 1
Important note #4: compiler_cmd
, compiler_cmd_double
, viewer
and viewer_images
are NOT required to be binaries. As my example configuration shows, they can be command lines (in my case, for a bash script). The downside of this is that no checks can be done before actually trying to run the provided command—so the onus is on you, the user, to ensure that whatever is provided on those configuration options, actually does work.
2. Overview
TeX-7 defines various mappings that speed up typesetting LaTeX code. Most of the mappings are prefixed with maplocalleader
, referred below with the symbol <LocalLeader>
. If you have set g:tex_seven_config.leader
, the corresponding character is used. Otherwise, it defaults to comma (,
).
Especially for multi-file projects, it is recommended to launch (g)Vim from the same folder where the main .tex
file is located. While most features should work fine even if you don’t do this, it is the best strategy to avoid unforeseen problems with relative paths. Besides, it’s the most natural thing to do anyway, so…
Below is a short introduction that should get you going in no time.
2.1 Normal mode
So, you have just been given an existing LaTeX project to work on. If you open the .tex
file on Vim, then typing <LocalLeader>V
will open the document in the PDF viewer configured in g:tex_seven_config
(see above). If you didn’t set g:tex_seven_config.viewer
, an error message is shown.2
If you are using multi-file projects, then hitting gm
will bring you back to the main .tex
file (mnemonic: “go to main file”). gM
will do the same, but it will open the main file on a new tab. Also useful for multi-file, there exist mappings ga
and gA
that will go the main file (always in the same tab) find the \includeonly
line, and:
ga
: Delete\includeonly
’s argument, place the cursor inside the{}
, and start completion.gA
: Append,
to\includeonly
’s argument, place the cursor at the}
character, and start completion.
To rename an enclosing environment, press <LocalLeader>R
. You’re prompted for a new environment name, and that gets replaced both in the \begin
and \end
lines of that enclosing environment. This works if the cursor is placed anywhere on the \begin
line, anywhere on the \end
line, or anywhere inside the environment (but not inside an inner nested environment, for in that case it is that inner environment’s name that gets replaced). It also works when either the \begin
or the \end
statements are not at the start of their respective lines.
Related to the above, for environments that have both a starred and a non-starred version, hitting <LocalLeader>T
swaps the “starred-ness.” For example, inside an equation environment, it will turn \begin{equation}
and \end{equation}
into \begin{equation*}
and \end{equation*}
, respectively—or vice-versa.
To go from from a \ref{
or \cite{
to its corresponding definition, place the cursor over them and hit either gp
or gd
: the first will open the corresponding \label{
or bib entry in a preview window (mnemonic: go preview), and the second in a new buffer (using :edit
; mnemonic: go to definition). Note that in the case of a preview window, the cursor will move to that window. To close it, hit :q
, as usual.
This functionality also works for things other than \label
’s and \cite
’s; see Jumping.
TeX-7 also makes it easy to move between the top/bottom of environments. If the current line is a \begin{
(resp. \end{
) line, typing <LocalLeader>%
takes the cursor to the corresponding \end{
(resp. \begin{
) line.3
Typing <LocalLeader>B
moves the cursor to the previous \begin{
line; <LocalLeader>E
does the same, but for the \end{
line. Typing <LocalLeader>b
moves the cursor to the next \begin{
line; <LocalLeader>e
does the same, but for the \end{
line. All these commands can be used in combination with the mappings to select/yank/move/etc. entire environments, as described below.
2.2 Insert Mode
To insert a command, press <LocalLeader><Space>
. \cmd
is inserted, with the cmd
part visually selected (select-mode, not visual-mode). So just type the command name. Then hit <Tab>
leave it like that—i.e., to finish the command without adding any arguments. To add optional arguments, hit ]
: a pair of brackets will be inserted, with the cursor in the middle: [|]
. To insert a mandatory argument, hit }
, without needing to move the cursor past the closing bracket; then a pair of curly braces will be inserted, with the cursor in the middle: {|}
. You can repeat this procedure for as many arguments as needed. Hit <Tab>
to finish: the cursor will be placed after the last }
of the command’s arguments, and you can continue typing your document.
Nested commands will also work, but in this scenario, the cursor will be left after the innermost }
. For example, if you use this feature to insert \footnote{\url{https://example.com}}
, the cursor will be left after the }
that closes the \url
command.
Note that both the mappings that set the <Tab>
key behaviour described above, as well as the mappings for <Esc>
and <C-c>
described below, are local (i.e., for the current buffer only). And after finishing typing the command (i.e., after pressing <Tab>
for the second time), they are either unset, or restored to their previous values.
If you want to interrupt the command insertion for whatever reason, then pressing <Esc>
or hitting <C-c>,
will clear all local maps of the <Tab>
key, restoring any previous mappings, if any (e.g. a mapping from a snippets plugin).
The local mapping of the <Esc>
key itself, that allows pressing it to unmap the <Tab>
key, is itself cleared when pressing <Esc>
. The same goes for <C-c>
. So long story short, this works as you would expect, without surprises.
And if for the cmd
part, you want to paste some text you have previously yanked/cut/etc, you can do that, by pressing <C-o>
, which will take you to visual mode, where you can then hit p
or P
. Then you will be left in insert mode—just if you had typed the text that you actually pasted—from where you can continue typing, or hit ]
or }
to continue inserting arguments, or hit <Tab>
to finish up.
Moving on, to insert an environment, press <LocalLeader>B
. You’re prompted for an environment name, then the following is inserted:
\begin{<envname>}
| \end{<envname>}
<envname>
is the supplied environment name; the cursor is left where the |
is, which means the first character the user types will be below the e
in the \begin
line. The list of environments comes from file ftplugin/environments.txt
. This can be customised; cf. below. Furthermore, by default the template for an environment is the one shown above, but it can be customised for specific environments (ibid.). This is done in file ftplugin/environments.snippets
. See the examples in that file, but the syntax is simple: to declare a new snippet, start with the word “snippet” at the start of the line, followed by a single space, followed by the name of the environment to be customised. If, after the environment’s name, there is a single space, followed by a number, than that is taken to be the line at the end of which the cursor will be placed, in insert mode. Any text can be added afterwords, to say, document the snippet; it will be ignored by TeX-7. For example, consider the snippet (<Tab>
’s are depicted with ->
):
snippet aligned 3 Multiple aligned equation with a single equation number
->\begin{equation}
->->\begin{aligned}
->->->
->->\end{aligned} ->\end{equation}
This will leave the cursor in such a position that the first character the user types will be below the e
in the inner \begin
, just as above.
Also as depicted in the example above, the other lines must start with a <Tab>
, and contain the snippet to be inserted for that environment. Note that no empty lines are allowed, for otherwise it would not be possible to detect where a snippet ended. However, as the example above also illustrates, lines with <Tab>
’s or other white space are not considered empty. The template code can thus contain indented lines, with tabs or spaces; upon insertion, the :retab
command is executed (only over the newly inserted lines).
Lastly, I should point out that, even though this feature was developed with LaTeX environments in mind, there is nothing preventing its use for other constructs the user might use frequently. This list of templates can also be customised; again, cf. below.
Onwards to another feature, type <LocalLeader>C
to insert a citation, i.e. \cite{citekey}
. You’re prompted with a pop-up list of completions if the \bibliography{}
(or \addbibresources{}
) statement contains a valid BibTeX file. Inserting references, \ref{ref}
, works in a similar way. The corresponding mapping is <LocalLeader>R
. Here are a few other mappings that work similarly:
<LocalLeader>A
inserts\includeonly{}
and starts completion inside the brackets.<LocalLeader>E
inserts\eqref{}
and starts completion inside the brackets.<LocalLeader>Z
inserts\includegraphics{}
and starts completion inside the brackets. Supported graphic types: JPG, PDF, PNG.
You can also, in the completion space, write some string (say “foo”), and hit <LocalLeader>K
. This will filter the original list of completions, to show you only those that contain the string “foo.” See Completion for more details.
Before moving on, let’s go back to <LocalLeader>C
for a moment, It often happens that, when inserting a reference, you also want to indicate a specific location within it (e.g., a page number). This is done with an optional argument to the \cite
command, e.g., \cite[p.\ 1]{foo}
. But hitting <LocalLeader>C
will leave you with \cite{foo|}
(the |
is the cursor). Not to worry: hit <LocalLeader>?
(in insert or normal mode, no matter), and you will be left in insert mode, with the cursor at the proper place to insert a specific location: \cite[|]{foo}
.
Moving on, there are also some macros that work by double tapping a character on your keyboard (super convenient for subscripts and superscripts!).
^^ -> ^{}
__ -> _{}
~~ -> \approx == -> &=
Furthermore, pressing <LocalLeader>"
inserts “LaTeX quotes,” i.e., ``''
. Also works for single quotes (with <LocalLeader>'
). And by default, hitting <LocalLeader>
twice (i.e. <Localleader><Localleader>
) inserts that character itself. E.g., if <LocalLeader>
is set to comma (,
), which is the default, then <Localleader><Localleader>
inserts a literal comma in the text.
There are plenty of other insert mode mappings; the ones described here are just the ones that required some explanation. See below.
2.3 Visual mode
TeX-7 comes with a custom “environment operator.” Press vie
or vae
in normal normal to highlight the current inner environment (without the \begin
and \end
statements) or the outer environment respectively. Replace v
with another operator to achieve yanking, changing or deleting etc. For example, typing dae
makes it trivial to move figures and tables around in the document. Delete the environment, find a new location and paste it back on the buffer!
Nota bene: this functionality requires that the \begin
and \end
commands are on different lines—which should be the case the vast majority of times. Nevertheless, I prefer to make the user explicitly aware of it.
Additionally, there are similar operators for inline math, i.e., math delimited by dollar signs ($
). For example, if you have $x = 1$
, then pressing vam
with the cursor anywhere in inside the dollar signs,4 will visually select all of it, including the delimiters. Hitting vim
does the same, but excludes the delimiters. And on for dam
, dim
, etc.
Also, given the ubiquity of curly (and even square) braces in LaTeX, there are operators these as well: ii
/aa
for inner/outer curly braces, and is
/as
for inner/outer square brackets. So for example, vii
selects the content inside curly braces, while vas
selects the content inside square brackets, as well as the brackets themselves.
Lastly, remember the normal mode <LocalLeader>B/E
and <LocalLeader>b/e
maps from above? Well, they can also be used for visual selections! For example, if in normal mode you hit V
—selecting the entire current line—and then <LocalLeader>e
, your visual selection will now encompass all lines from the starting one up to and including the line of the next \end{
statement.
3. Compilation and Multi-file
3.1 Compilation
At the beginning I talked about a “save-and-compile” process. This means a one-time run of the LaTeX compilation program or script. Other compilation cycles, like a “full build” that also constructs the bibliography, are outside of the scope of the this plugin. This is because compilation of LaTeX files is very tricky to get right in all circumstances, and after all, Vim is not an IDE.5
Now, as any LaTeX user knows (and as novice users quickly find out), LaTeX’s error messages can be notoriously hard to interpret correctly… and this might be putting it mildly! So what one usually does is save and build often, so that if any errors do occur, it is easier for the user to pinpoint the change that caused it. To aid in this task, this plugin defines a normal mode mapping :ww
, that saves the current file, and does a small compile of the LaTeX project. So instead of writing (:w
), the user can instead do a write-and-build, relatively seamlessly (:ww
). This build is done in background, and if it succeeds, nothing more is said to the user, who can just continue to work. He is only notified if errors occur, so that he can go fix them, before writing any more.
Moreover, it also happens with some frequency that two compile runs are required for some change to take effect (e.g. updates to the table of contents, \ref
’rencing new \label
’s, etc.). For this, the plugin provides the normal mode mapping :w2
. The command actually used is the one supplied by the compiler_cmd_double
config option. If no such command is supplied, then the one in compiler_cmd
is used twice.
3.2 Multi-file Projects
In order to work with LaTeX projects containing multiple files, each file other than the main one (the one containing the \documentclass
line) must contain a modeline indicating the relative location of the main .tex
file. E.g., if your main file is named main.tex
, and it includes a file with relative path chapters/introduction.tex
, then this file must contain a modeline similar to:
% mainfile: ../main.tex
The modeline must appear either on the three first lines of the file, or on the three last. Also note that the relative path must not contain spaces!
4. Jumping
TeX-7 allows you to, for example, preview a bibliographic reference, by placing the cursor somewhere over the \cite{...}
command, and hit gp
: the corresponding BibTeX entry is then shown in a preview window. There are many other possibilities, besides bibliographic references. All of them are described in this section. Before that, an important note: all the features described here using gp
, also work with gd
, with the difference that in the latter case, no preview window is opened (i.e., :edit
is used instead of :pedit
).
Also note that when using gp
, to close the preview window after having placed the cursor in some other window, there is no need to go back to the preview window. Just hit gb
, which is an alias to :pclose
(mnemonic: Go Back to when there was no preview window opened). When using gd
, to go back hit CTRL-o
. All in normal mode.
Furthermore, gf
is an alias to gd
. See section Includes below for the reason for this.
4.1 Citations
If you have a citation like \cite[some note]{key}
, or \nocite{key}
, or some other \cite-like
command, then placing the cursor anywhere, even outside of the key
part, and pressing gp
will open a preview window displaying the bib entry corresponding to that key.
If you have a citation like \cite{key1, key2}
, or \cite[some note]{key1, key2}
, if you press gp
when the cursor is over key1
, or key2
, then the corresponding bib entry will be shown. If the cursor is before the first key, e.g. over the \cite{
string, then the entry for that first key is shown (in this case key1
). If the cursor is inside the curly braces, but not over any key, then the first preceding key is used. In the example, if the cursor is at the comma or the space inside the curly brackets, key1
is used. If the cursor is at the closing bracket }
, then key2
is used.
4.2 Labels and References
If you have a reference like \ref{key}
, or \eqref{key}
, or any other \ref-type
command, then placing the cursor anywhere, even outside of the key
part, and pressing gp
will open a preview window showing the corresponding \label{key}
statement.
4.3 Includes
If you have a line like \include{filename}
, or \includeonly{filename}
, then placing the cursor anywhere, even outside of the “filename” part, and pressing gp
will show the file named filename
in the preview window.
As stated above, gf
is an alias to gd
. The reason for this is that by default, hitting gf
when the cursor is over a file name/path makes Vim open that file in a new buffer (if the file exists). So to jump between files, I thought that the gf
map might feel more natural (it does to me). Of course, this also means that you can use gf
to, say, jump from a \ref
to the corresponding \label
. Use whatever shortcut suits you best!
4.4 Graphics
If you have a line like \includegraphics{graphicfilename}
, then placing the cursor anywhere, even outside of the graphicfilename
part, and pressing gd
or gp
will open graphicfilename
using the application configured in g:tex_seven_config.viewer
for PDF files, and g:tex_seven_config.viewer_images
for JPG or PNG files (see above). If you didn’t set g:tex_seven_config.viewer
, and/or g:tex_seven_config.viewer_images
, an error message is shown.
4.5 Sections and Subsections
In normal mode, hitting <LocalLeader>S
takes you to the previous uncommented \section{
declaration. <LocalLeader>s
takes you to the next such uncommented declaration.
<LocalLeader>U
and <LocalLeader>u
do the same, but for uncommented \subsection{
declarations.
5. Completion
Say you have the following text in a .tex
file: \ref{|}
, with the cursor being in the position of |
(in insert mode). If you press vim
will show you a pop-up, containing all keys corresponding to \label{key}
statements found in the main .tex
file, and any files \include
’d therein, if any. Furthermore, if what is actually in your .tex
file is something like: \ref{sec:|}
, then the pop-up will show only label keys that start with the prefix sec:
.
Pretty nice, right? This is called completion. What I described above is a part of so-called “omni-completion.” The other is completion of math paraphernalia, creatively named “math-completion.” Both are described in the following sections.
Note that as in the example above, all completion scenarios described below always take place in insert mode. Also, |
is used to denote the cursor’s position.
Perl script for \label
retrieval. Retrieval of \label
statements, is done using an external Perl script. When opening a file, the external script is launched in the background, to retrieve all \label
statements, across all project .tex
files. Thus, triggered completion will be a quicker process. (Recall that this external script requires that Perl be installed, together with the perl-json
module, as stated above).
5.1 Omni-Completion
The above introduction already covers the case of omni-completion for \ref{
; completion for \eqref{
works in the same way. Completion for \label{
is also done: it returns the list of existing \label
’s (i.e., it returns the same thing as for \ref{
and \eqref{
). The rationale for the omni-completion of \label
statements is that one might want to create a new label using as a prefix the name of an existing label. For example, for sections inside chapters, I prefix the label of the section with the label of the chapter. This avoids label clashes for situations where, for instance, more than one chapter has a section named “Introduction.”
Completion for \includeonly{
and \includegraphics{
are similar, with the difference that what is returned are list of files \include
’d in the main .tex file (if any), and graphic files, respectively. The graphic files are searched in the folder that contains the main .tex
file, and any subfolders therein (but note that any files inside folders with names containing the string “build” are ignored).
In all the cases described here, if there is a base text (e.g. the sec:
in \ref{sec:|}
), then only matches that contain that base string are returned, just as explained above. For example, suppose you hit <LocalLeader>A
. \includeonly{|}
gets inserted, and completion entries shown. If you then type foo
, by default Vim will show you the entries that start with foo
. But if you then hit <LocalLeader>K
, TeX-7 will show you all the entries that contain the string “foo,” even if not at the beginning. However, the text foo
that you typed is deleted (after all, the matching entries might not all begin with that string). And you can do this with more than one word! For example, if your write \ref{foo bar|}
and then hit <LocalLeader>K
, the entries shown will be only the ones that contain both the string “foo” as well as the string “bar,” though not necessarily in that order. Of course, you can use more than two strings (e.g., \ref{foo bar baz|}
).
Warning #1: After doing a selection, with the possible completions showing, if you type anything, this will select, of the completions shown, only those that start with what you just typed!
Warning #2: Say you have a base text of foo
, hit <LocalLeader>K
, and are shown a completion list containing fooa
and foob
. If you now attempt to delete the last o
, the behaviour is inconsistent: Vim might only delete the last o
, leaving you with a base text of fo
, and a completion list containing only results that start with fo
(and not results containing the string fo
in other places other than the beginning). Or Vim might delete the entire base text (foo
), and use it to perform completion: i.e., display a list of completions that contain “foo” as a substring (not necessarily at the beginning).6
So to be safe, ALWAYS REDO THE SEARCH AFTER MODIFYING THE BASE TEXT!!
5.2 Math-Completion
Type <LocalLeader>M
to get a pop-up list of different maths symbols, together with their shape (e.g. \alpha
corresponds to α
). I have (mostly) chosen to put on the completion list (~/.vim/autoload/tex_seven/omniMath.vim
) symbols that have an Unicode representation, and can hence be “previewed” in this fashion.
Furthermore, if there is a word to the left of the cursor, that word is used to filter the results of the pop-up list. For example, if you write $x arrow|$
and press <LocalLeader>M
, the pop-up list will contain all math symbols containing, but not necessarily starting with, the string “arrow.” This also works if you write \arrow
. In both cases, you get a command, i.e., if you write arrow
or \arrow
, hit <LocalLeader>M
, and then select rightarrow
from the completion pop-up, you get the command \rightarrow
.
Additionally, the most frequently used maths symbols have their own shortcuts. Typing <LocalLeader>a
expands to \alpha
for example. See below for a complete listing.
6. Tips and tricks
6.1 Override, extend and hack TeX-7
Create a custom tex.vim
file in the after/
directory, i.e. ~/.vim/after/ftplugin/tex.vim
. Here you can redefine mappings and extend TeX-7’s functionality with your own ideas. If you come up with something sweet, kindly drop me a line 🙂
Notice that to redefine mappings, you need need to set <LocalLeader>
again. As an example, here is my ~/.vim/after/ftplugin/tex.vim
:
" First, reset <LocalLeader>. Note that this will run *after* TeX-7, and hence
" the variable g:tex_seven_config.leader will be set.
if exists('g:maplocalleader')
let s:maplocalleader_saved = g:maplocalleader
endif
let g:maplocalleader = g:tex_seven_config.leader
" Now, implement user's customisations. In this case, override of selected
" TeX-7 mappings.
inoremap <buffer> <LocalLeader>e \varepsilon
inoremap <buffer> <LocalLeader>_e \epsilon
inoremap <buffer> <LocalLeader>_0 \emptyset
inoremap <buffer> <LocalLeader>0 \varnothing
" I find this easier to insert environments in .tex files (something I do often).
inoremap <buffer><silent> ;; <C-r>=tex_seven#environments#InsertEnvironment()<CR>
inoremap <buffer> <LocalLeader>;; ;;
" And lastly, revert <LocalLeader> to its previous setting, if any.
if exists('s:maplocalleader_saved')
let g:maplocalleader = s:maplocalleader_saved
unlet s:maplocalleader_saved
else
unlet g:maplocalleader endif
6.2 Custom environment list/templates
You may have noted that the default list of environment names, as well as the provided snippets, are a bit lacking. This is by design: it is something that really varies with the needs of the user. So instead of trying to provide some “defaults” that would be acceptable to most, I just provide a bare skeleton of both, and encourage the user the customise them to suit his needs.
To set a custom list of environment names for using during environment insertion, first create a folder named tex_seven
in ~/.vim/after/ftplugin/
. Then copy TeX-7’s environment names file (ftplugin/environments.txt
) to that folder, and customise it to suit your needs. And finally, in ~/.vim/after/ftplugin/tex.vim
, insert:
let b:env_list = fnameescape(expand('<sfile>:h') . '/tex_seven/environments.txt')
Environment name completion will now use your name list, rather than TeX-7’s default list. A similar trick can be used to customise environment templates: copy TeX-7’s environment snippets file (ftplugin/environments.snippets
) to the same place as above, and customise it to suit your needs. Then add the following to ~/.vim/after/ftplugin/tex.vim
:
let b:env_snippets = fnameescape(expand('<sfile>:h') . '/tex_seven/environments.snippets')
The snippets used during environment insertion will now be from your customised file, rather than TeX-7’s default snippet file. As an example, here are my environments.txt and environments.snippets files.
6.3 Spell checking
If you’ve enabled modeline
, you may conveniently activate spell checking (among other settings) in your LaTeX documents, like so (example for anglophones):
% vim: spell spelllang=en
Notice that newer versions of Vim provide an option for disabling spell checking of comments that otherwise get messed up pretty badly:
let g:tex_comment_nospell=1
6.4 Pedantic Styling
Some people think that closing quotation marks, whether double or single, should always come AFTER any punctuation marks. However, this is annoying to do while is writing… Hence, the plugin provides the :SwapQuotesPunctuation
command, that does, well, just that: replaces ''.
with .''
(for dots, commas, colons, and question and exclamation marks). Then it replaces '.
with .'
(idem). Works even when the punctuation mark ends the line.
In addition to this, I define a command \kk
, as follows:
\newcommand*{\kk}{\kern-0.15em}
Then, if I write .\kk''
, the double inverted commas will be shifted to the left a little bit, so as to partially “cover” the empty space above the dot. This is called kerning, and I also do it for commas. I think it improves the visual pleasantness of the text. Hence, TeX-7 provides the kerning_cmd
, which, when provided, makes SwapQuotesPunctuation()
replace ''.
with .\kk''
—for both single and double inverted commas, but only for dots and commas (colons, question and exclamation marks are only swapped).
7. Mappings
Here is an overview of the provided maps. This information can also be accessed from within Vim, via the command :help vim-tex-seven
. Keep in mind that these mappings can be customised; see above for an example.
Where applicable, |
indicates the cursor position after the map insertion (where no |
is shown, the cursor is placed immediately after the inserted text).
7.1 Normal Mode
ga
: Go to main file, replace\includeonly{}
line with that command and start completiongA
: Same asga
, but go to main file in a new tabgb
: Go back from preview window (alias to:pclose
)gd
: Go from\ref
to the corresponding\label
declaration, or similargf
: Go to, say, an\include{file}
, or similargm
: Go to main file, in the same tabgM
: Go back to main file, in a new tabgp
: Same asgd
/gf
, but show on a preview window, if applicable (obviously this does not apply when, say, displaying an image file)<LocalLeader>A
: Go to main file, place cursor at\includeonly{}
line<LocalLeader>B
: Go to corresponding\begin
above<LocalLeader>b
: Go to next\begin
above<LocalLeader>E
: Go to corresponding\end
below<LocalLeader>e
: Go to next\end
below<LocalLeader>R
: Rename environment<LocalLeader>T
: Toggle starred/unstarred environment<LocalLeader>V
: View the document:ww
: Do a small compile (see compilation):w2
: Do two small compiles (see compilation)
7.2 Insert Mode
In the mappings below, whenever completion is available (e.g. for \ref
), it is started. Cf. completion for details.
<LocalLeader><LocalLeader>
:<LocalLeader>
<LocalLeader>'
: LaTeX’s inverted single commas `'
<LocalLeader>"
: LaTeX’s inverted double commas``''
<LocalLeader>?
: Go from\cite{foo|}
to\cite[|]{foo}
<LocalLeader>A
: Insert\includeonly{}
, and start completion<LocalLeader>B
: Insert environment (prompts for a name)<LocalLeader>C
: Insert\cite{}
, and start completion<LocalLeader>E
: Insert\eqref{}
(equation reference), and start completion<LocalLeader>K
: Start regular (non-math) completion<LocalLeader>M
: Start math completion<LocalLeader>R
: Insert\ref{}
, and start completion<LocalLeader>Z
: Insert\includegraphics{}
reference
Greek letters:
<LocalLeader>a
:\alpha
<LocalLeader>b
:\beta
<LocalLeader>c
:\chi
<LocalLeader>d
:\delta
<LocalLeader>e
:\epsilon
<LocalLeader>f
:\phi
<LocalLeader>g
:\gamma
<LocalLeader>h
:\eta
<LocalLeader>i
:\iota
<LocalLeader>k
:\kappa
<LocalLeader>l
:\lambda
<LocalLeader>m
:\mu
<LocalLeader>n
:\nu
<LocalLeader>o
:\omega
<LocalLeader>p
:\pi
<LocalLeader>q
:\theta
<LocalLeader>r
:\rho
<LocalLeader>s
:\sigma
<LocalLeader>t
:\tau
<LocalLeader>u
:\upsilon
<LocalLeader>w
:\varpi
<LocalLeader>x
:\xi
<LocalLeader>y
:\psi
<LocalLeader>z
:\zeta
<LocalLeader>D
:\Delta
<LocalLeader>F
:\Phi
<LocalLeader>G
:\Gamma
<LocalLeader>L
:\Lambda
<LocalLeader>O
:\Omega
<LocalLeader>P
:\Pi
<LocalLeader>Q
:\Theta
<LocalLeader>U
:\Upsilon
<LocalLeader>X
:\Xi
<LocalLeader>Y
:\Psi
<LocalLeader>\_e
:\varepsilon
<LocalLeader>\_q
:\vartheta
<LocalLeader>\_r
:\varrho
<LocalLeader>\_s
:\varsigma
<LocalLeader>\_f
:\varphi
Mathematical symbols.
<LocalLeader>\
:\setminus
<LocalLeader>½
:\sqrt{|}<Left>
<LocalLeader>N
:\nabla
<LocalLeader>S
:\sum_{|}^{}<Esc>2F{a
<LocalLeader>_S
:\prod_{|}^{}<Esc>2F{a
<LocalLeader>V
:\vec{|}<Left>
<LocalLeader>I
:\int\limits_{|}^{}<Esc>2F{a
<LocalLeader>0
:\emptyset
<LocalLeader>_0
:\varnothing
<LocalLeader>6
:\partial
<LocalLeader>Q
:\infty
<LocalLeader>/
:\frac{|}{}<Esc>2F{a
<LocalLeader>|
:\lor
<LocalLeader>&
:\land
<LocalLeader>||
:\bigvee
<LocalLeader>&&
:\bigwedge
<LocalLeader>@
:\circ
<LocalLeader>*
:\not
<LocalLeader>!
:\neq
<LocalLeader>~
:\neg
<LocalLeader>=
:\equiv
<LocalLeader>-
:\cap
<LocalLeader>+
:\cup
<LocalLeader>--
:\bigcap
<LocalLeader>-+
:\bigcup
<LocalLeader>~
:\widetilde{|}<Left>
<LocalLeader>^
:\widehat{|}<Left>
<LocalLeader>_
:\overline{|}<Left>
<LocalLeader><CR>
:\nonumber \\<CR>
<LocalLeader>«
:\langle
<LocalLeader>»
:\rangle
<LocalLeader>(
:\left( | \right)<Esc>F(la
<LocalLeader>[
:\left[ | \right]<Esc>F[la
<LocalLeader>{
:\left\{ | \right\}<Esc>F{la
<LocalLeader>>
:<|><Left>
<LocalLeader><
:\langle | \rangle<Esc>F\hi
The last two mappings above are as I prefer them. However, by setting the configuration flag diamond_tex
to 0 (see Installation), you can revert them to TeX-9’s original mappings:
<LocalLeader><
:\leq
<LocalLeader>>
:\geq
7.3 Visual Mode
Besides the operator for selecting environments, inline mathematics and braces (see above), the following mappings allow you to quickly change the style of already existing text.
<LocalLeader>b
(Bold): Wrap selection in\textbf{}
or\mathbf{}
<LocalLeader>m
(eMphasis): Wrap selection in\emph{}
<LocalLeader>i
(Italic): Wrap selection in\textit{}
or\mathit{}
<LocalLeader>r
(Roman): Wrap selection in\textrm{}
or\mathrm{}
<LocalLeader>a
(sAns serif font): Wrap selection in\textsf{}
or\mathsf{}
<LocalLeader>t
(Teletype): Wrap selection in\texttt{}
or\mathtt{}
<LocalLeader>u
(Upright in math mode): Wrap selection in\text{}
<LocalLeader>q
(Single quotes): Wrap selection in `'
<LocalLeader>Q
(Double Quotes): Wrap selection in``''
For example, to emphasise the word under the cursor to boldface, type:
viw<Leader>m
December 1, 2023. Got feedback? See the contact page.
* * *
Update, November 21, 2023. The plugin’s full manual is now displayed here. Within Vim, hitting :help vim-tex-seven
will only list the available maps, visual mode motions, etc., together with brief descriptions of each—and direct the user to the current page for further information.