I recently made myself custom insert mode keybindings to type faster in LaTeX. However, When I use them, Vim adds tabs that weren't part of the original keybinding.


Here is my inoremap:

autocmd FileType tex inoremap ;t \begin{table}<Enter>\caption{}<Enter>\label{<++>}<Enter>\begin{center}<Enter>\begin{tabular}{<++>}<Enter>\toprule<Enter><++><Space>\\<Enter>\toprule<Enter><++><Space>\\<Enter><++><Space>\\<Enter>\bottomrule<Enter>\end{tabular}<Enter>\end{center}<Enter>\end{table}<Enter><Enter><++><Esc>?caption{<Enter>8li

This is the output (<X> is the final location of my cursor):

 <++> \\
 <++> \\
 <++> \\


Why isn't everything lining up at the beginning of the line? (the previous lines are not indented)



I know that it would be more appropriate to use functions instead of mapping but I haven't learned them yet...


1 Answer 1


Snippet plugin instead of a simple inoremap

If you are interested in features like jumping from one placeholder to another one, you might be interested in using a plugin. There are many options you can choose from. There are a few dedicated to LaTeX:

  1. vim-latex (details in section 3.12 and plugin/imaps.vim)

    You can also install only plugin/imaps.vim with
    $ wget https://raw.githubusercontent.com/vim-latex/vim-latex/master/plugin/imaps.vim -O ~/.vim/plugin/imaps.vim
    and then define in ~/.vim/after/ftplugin/tex.vim:

    call IMAP('ETE', "\\begin{table}\<CR>\\caption{<++>}\<CR>\\label{<++>}\<CR>\\begin{center}\<CR>\\begin{tabular}{<++>}\<CR>\\toprule\<CR><++><Space>\\\\\<CR>\\toprule\<CR><++><Space>\\\\\<CR><++><Space>\\\\\<CR>\\bottomrule\<CR>\\end{tabular}\<CR>\\end{center}\<CR>\\end{table}\<CR>\<CR><++>", 'tex')
  2. latex-support
  3. quicktex

There are also a few plugins which provide a fixed set of snippets for LaTeX (however, you can always modify the source code):

  1. auctex.vim
  2. drcstubs
  3. texmaps

I personally prefer a general plugin such as

  1. Ultisnips
  2. snipmate
  3. neosnippet

Your insert mode mapping as a ultisnips snippet (e.g. placed in ~/.vim/UltiSnips/tex.snippets):

snippet table "Table & Tabular"
  \caption{${1:<+Caption text+>}}
    $4 \\
    ${5:${VISUAL}} \\

A more advanced snippet request is the question Easiest way to insert LaTeX matrix?.

You find also similar ones predefined in snippet collections such as

The question What is the difference between the vim snippets plugins? could also be interesting to compare the different options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.