TeX-7

github repo: https://github.com/notnotrandom/vim-tex-seven

This is my toned-down fork from Elias Toivanen's TeX-9 vim plugin for writing LaTeX documents. I liked it 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. Hence I rewrote it in pure Vimscript (TeX-9 used Python bindings), and added a couple of sweet features (e.g., smarter completion, and distraction-free background save-and-compile—just hit '<Esc>:ww' (sans quotes). Feedback will only be shown in case of error).

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.

Hereinafter is an overview of its bird's eye explanation of its basic features, taken straight from the plugin's documentation. (Slightly edited to work around markdown's restrictions; see https://github.com/notnotrandom/vim-tex-seven/blob/master/doc/tex_seven.txt for the whole document).


2. Basics

TeX-7 defines various mappings that speed up typesetting LaTeX code. Most of the mappings are prefixed with a leader referred below with the symbol . If you have set g:tex_seven_config.leader, the corresponding character is used. Otherwise, if it is set, |maplocalleader| is used. As a last resort, the leader defaults to colon (:).

Especially for multi-file projects, it is recommended to lauch (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 tutorial that should get you going in no time.

2.1 Insert mode

To insert an environment, press <LocalLeader>B. You're prompted for an environment name, then the following is inserted:

\begin{<envname>}
  |
\end{<envname>}

is the supplied environment name; the cursor is left where the | is.

To insert a command, press <LocalLeader><Space>. "\cmd{arg}" is inserted (sans quotes), with the "cmd" part visually selected. So just type the command name. Then just hit <Tab>, to move to the "arg" part, which will be left visually selected, for you type over. After that, hitting <Tab> once more will move the cursor to the right of the now finished command (i.e., after the '}'), so you can continue to type your LaTeX document.

Note that mappings that set the <Tab> key behaviour described above are local (for the current buffer only), and are unset after finishing typing the command (i.e., after pressing <Tab> for the second time). However, if you want to interrupt the command insertion for whatever reason, then pressing <Esc> will clear all local maps of the <Tab> key, restoring any previous mappings, if any (e.g. a snippets plugin).

Also note that the local mapping of the <Esc> key itself, that allows pressing it to unamp the <Tab> key, is itself cleared when pressing <Esc>. So long story short, this works as you would expect, without surprises.

Moving on, type <LocalLeader>C to insert a citation, i.e. \cite{citekey}. You're prompted with a popup 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:

There are also some macros that work by double tapping a character on your keyboard (super convenient for subscripts and superscripts!).

Furthermore, pressing <LocalLeader>" inserts "LaTeX quotes", i.e.,``''. Also works for single quotes. And by defaut, hitting <LocalLeader> twice (i.e. <Localleader><localleader>) inserts that character itself. E.g., if <LocalLeader> is set to colon (:) (the default without user config and maplocalleader defined), then <Localleader><localleader> inserts a literal colon in the text.

2.2 Normal mode

Typing <LocalLeader>V should 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.

If you are using multi-file projects (see |tex_seven-compile-mfile|), then hitting <LocalLeader>gm will bring you back to the main .tex file (mnemonic: "go to main file").

To go from from a \label{ or \cite{ to its corresponding definition, place the cursor over them and hit either gp or gd: the first will open the corresponding \ref{ 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 does NOT move to that window. To close it, hit gb (mnemonic: go back).

This functionality also works for things other than 's and 's; see |tex_seven-jumping|.

Typing <LocalLeader>B should move the cursor to the first line opening an environment ("\begin{"), that is above the current line (the line where the cursor is). Similarly, typing E should move the cursor to the first line ending an environment ("\end{"), that is below the current line. Both are super useful when used in combination with the mappings to select/yank/move/etc. entire environments, as described next. Especially in the case of nested environments, when the cursor is positioned at the innermost environment, but you want to select, say, the outermost.

2.3 Visual mode

TeX-7 comes with a custom environment operator (see ||text-objects||). 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 to the buffer!

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 that inline math expression, will visually select all of it, including the delimiters. Hitting 'vim' does the same, but excludes the delimiters. And on for 'dam', 'dim', etc.