# lstlisting: highlighting for vimscript

I would like to document some scripts written in vimscript. How can I do this with the listing package? I haven't found a supported language by listings for vimscript.

Example to set with lstlisting:

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start


Thank you very much!

• Welcome to TeX.SX! As it does not seem to be a default language, have you tried to make up one yourself? If yes, it would be great, if you could share your attempt. – TeXnician Sep 17 '17 at 16:18
• Thank you for your answer! I wrote my own definitions (see answer below). – Theova Sep 19 '17 at 19:39

The listings package does not support vimscript out of the box. You'd have to write your own highlighting rules. Here I present an alternative, which is the minted package. It uses the external program pygmentize to format source code and therefore needs shell escape (and pygmentize installed of course). It is also recommended to use an alternative font, like lmodern which comes with bold teletype font. In my opinion the results are much better than with listings.

\documentclass{article}
\usepackage{lmodern,minted}
\begin{document}

\begin{minted}{vim}
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
\end{minted}

\end{document}


• Thank you. As I'm facing problems with minted (error: /usr/local/texlive/2017/texmf-dist/tex/latex/ifplatform/ifplatform.sty|54 error| Argument of " has an extra }. ), I'm looking for a solution with the for me known listings. – Theova Sep 19 '17 at 19:21

I started to write my own definition for vim. Here you see my first approach:

    \lstdefinelanguage{vim}
{
% list of keywords
morekeywords={
set, let
map, nmap,
filetype,
on, off,
autocmd,
Plugin,
call,
},
morecomment=[l]{"}, % l is for line comment
morestring=[b]' % defines that strings are enclosed in double quotes
}