summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/context/third/vim/vim.txt
blob: 251565547fc5bdc950adc411a5d7e99d621a4871 (plain)
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
The vim module
==============

ConTeXt has excellent code highlighting capabilities for some languages: TeX,
metapost, XML, amongst others. In MkII, syntax highlighting was done by parsing
the source code in TeX---a task not for the faint of heart. In MkIV, the
situation is much better: syntax highlighting is done by parsing the source code
in Lua using LPEG. Nonetheless, writing a grammar to parse the source code of
languages is a tricky task. This module takes the onus of defining such a
grammar away from the user and uses Vim editor to create syntax highlighting. A
helper script, `2context.vim` does the actual work.

The idea of the module was germinated  by Mojca Miklavec. She said (crica Sep
2005):

> I am thinking of piping the code to vim, letting vim process it, and return
> something like `highlight[Conditional]{if} \highlight[Delimiter]{(}
> \highlight[Identifier]{!}`.


> One could modify the `2html.vim` file. Vim can already transform the highlighted
> code to HTML, so ConTeXt should not be so difficult. Vim already has over 400
> syntax file definitions, probably equivalent to some hundred thousand lines of
> syntax definition in ConTexT. Well, I don't know (yet) how to do it, but if
> someone on the last has more experience with vim, please feel free to
> contribute. 

A few months later (circa Dec 2005), Nikolai Webull provided such a modification
of `2html.vim` and called it `2context.vim`. That file was the foundation of
`t-vim` module. 

About two years later (circa June 2008), Mojca and I (Aditya Mahajan) pickup up
on this idea and released `t-vim`. Over the next few years, nothing much changed
in the module, except a few minor bug fixes. 

Around June 2010, I decided to completely rewrite the module from scratch. It
now uses the `t-filter` module behind the scenes for all the book-keeping of
creating and maintaining external files.

Installation
------------

You also need to install `t-filter` module.

Basic Usage
-----------

The main macro of this module is `\definevimtyping`. Suppose you want to do
syntax highlighting of ruby code in ConTeXt. For that you may use:

    \definevimtyping [RUBY]  [syntax=ruby]

This defines an environment

    \startRUBY
      ...
    \stopRUBY

The contents of this environment are written to an external file, which is then
parsed using vim, and the output is read back by ConTeXt.