Difference between revisions of "Vim"

From Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
http://www.vim.org/
 
http://www.vim.org/
  
This page is about editing ConTeXt source in Vim, gVim, MacVim, NeoVim, and other Vim clones. Some of the described features are available only in Vim v8.0.0047 or later: they will be noted below.  
+
This page is about editing ConTeXt source in Vim, gVim, MacVim, NeoVim, and other Vim clones.
 
+
The page describes the scripts available with Vim v8.0.0047 or later.
== A note on filetype detection ==
+
If you are using an older Vim, you may copy the scripts from Vim's distribution
 
+
(https://github.com/vim/vim), under the <tt>runtime</tt> directory. Everything should work, at
TeX (Plain TeX), LaTex and ConTeXt all use the <tt>.tex</tt> extension for files, which makes it difficult to detect the filetype based on the extension. From Vim 7 onwards, Vim does some intelligent checking to see it the file is <tt>plaintex</tt> or <tt>latex</tt> or <tt>context</tt>.
+
least with Vim 7.4.
 
 
If the first line of a <tt>*.tex</tt> file has the form
 
%&<format>
 
then this determines the file type: <tt>plaintex</tt> (for Plain TeX), <tt>context</tt> (for
 
ConTeXt), or <tt>tex</tt> (for LaTeX). Otherwise, the file is searched for keywords to
 
choose <tt>context</tt> or <tt>tex</tt>.  If no keywords are found, it defaults to <tt>plaintex</tt>.
 
You can change the default by defining the variable <tt>g:tex_flavor</tt> to the format
 
(not the file type) you use most.  Use one of these:
 
let g:tex_flavor = "plain"
 
let g:tex_flavor = "context"
 
let g:tex_flavor = "latex"
 
Currently no other formats are recognized.
 
 
 
* If you use ConTeXt most of the time, but occasionally use LaTeX or Plain TeX, you can add the following to your <tt>.vimrc</tt>
 
let g:tex_flavor = "context"
 
* If you only use ConTeXt, you can add the following lines to <tt>filetype.vim</tt>:
 
" ConTeXt
 
augroup filetypedetect
 
au! BufRead,BufNewFile *.tex setfiletype context
 
augroup END
 
so the next time you open a <tt>*.tex</tt> file, Vim will always recognize it as a ConTeXt document.
 
 
 
== A note on spell checking ==
 
 
 
Vim 7 or later has a built-in spell checker. To enable it or disable it, use:
 
:set spell
 
or
 
:set nospell
 
respectively.
 
To set the language to be used for spell checking, set the <tt>spelllang</tt> option accordingly. For example:
 
:set spelllang=en_us
 
Use lowercase letters (<tt>en_us</tt>, not <tt>en_US</tt>). When you set <tt>spelllang</tt>, Vim offers to
 
download the language data into your <tt>.vim</tt> folder, if such language is not available.
 
You can put the above settings in your <tt>.vimrc</tt> if you like.
 
  
 
== Using ConTeXt in Vim ==
 
== Using ConTeXt in Vim ==
Line 56: Line 22:
 
The recommended way to typeset a ConTeXt document is to use the <tt>:ConTeXt</tt> command. Just type:
 
The recommended way to typeset a ConTeXt document is to use the <tt>:ConTeXt</tt> command. Just type:
 
  :ConTeXt
 
  :ConTeXt
to typeset the document in the current buffer. Typesetting happens in the background if you are using Vim 8.0.0047 or later,
+
to typeset the document in the current buffer.
 +
Typesetting happens in the background if you are using Vim 8.0.0047 or later,
 
so you may continue working on your document. If there are errors, the quickfix window opens automatically
 
so you may continue working on your document. If there are errors, the quickfix window opens automatically
to show the errors (one error per line). The cursor stays in the main document, so your typing workflow is not
+
to show the errors (one per line). The cursor stays in the main document, so your typing workflow is not
 
disrupted. You may use standard quickfix commands to jump between errors: <tt>:cfirst</tt>, <tt>:cprev</tt>,
 
disrupted. You may use standard quickfix commands to jump between errors: <tt>:cfirst</tt>, <tt>:cprev</tt>,
<tt>:cnext</tt>, etc… (see <tt>:help quickfix</tt>). It is useful to add mappings for these commands. For example:
+
<tt>:cnext</tt>, etc… (see <tt>:help quickfix</tt>). See below for useful mappings for these commands.
  nnoremap <silent> ]q :<c-u><c-r>=v:count1<cr>cnext<cr>zz
 
  nnoremap <silent> [q :<c-u><c-r>=v:count1<cr>cprevious<cr>zz
 
Or install Tim Pope's <i>unimpaired</i> plugin.
 
  
 
If your document is typeset without errors, <tt>Success!</tt> is printed at the bottom of the screen.
 
If your document is typeset without errors, <tt>Success!</tt> is printed at the bottom of the screen.
Line 73: Line 37:
 
running jobs with <tt>:ConTeXtStopJobs</tt> (these commands are available only in Vim 8.0.0047 or later).
 
running jobs with <tt>:ConTeXtStopJobs</tt> (these commands are available only in Vim 8.0.0047 or later).
  
An alternative way to typeset a document is to use <tt>:make</tt>. Make sure that the current working
+
An alternative way to typeset a document is to use <tt>:make</tt>. Set the current working
directory is set to the path to the file you want to compile (set with <tt>:lcd …</tt>), and type:
+
directory to the directory of the current buffer, then execute <tt>:make</tt>:
 +
lcd /path/to/my/project
 
  :make
 
  :make
If a <tt>Makefile</tt> is present in the working directory, it will be used (you may
+
If a <tt>Makefile</tt> exists in the working directory, it is used (see below for a sample Makefile).
<tt>let g:context_ignore_makefile=1</tt> to ignore it). Otherwise, <tt>mtxrun</tt> will
+
You may <tt>let g:context_ignore_makefile=1</tt> to ignore an existing Makefile.
be invoked directly. Note that <tt>:make</tt> always performs synchronous typesetting. Also, if there are
+
If no Makefile is found, <tt>mtxrun</tt> will be invoked directly.
 +
Note that <tt>:make</tt> always performs synchronous typesetting. Also, if there are
 
errors, the quickfix list is populated, but you have open it manually with <tt>:copen</tt>.
 
errors, the quickfix list is populated, but you have open it manually with <tt>:copen</tt>.
  
Line 85: Line 51:
 
to your <tt>.vimrc</tt>, or (better)
 
to your <tt>.vimrc</tt>, or (better)
 
   nnoremap <buffer> <silent> <leader>tt :<c-u>update<cr>:ConTeXt<cr>
 
   nnoremap <buffer> <silent> <leader>tt :<c-u>update<cr>:ConTeXt<cr>
to <tt>~/.vim/after/ftplugin/context.vim</tt>, after which pressing <tt>\tt</tt> (where <tt>\</tt> is your leader key) will save (if necessary) and compile the file.
+
to <tt>~/.vim/after/ftplugin/context.vim</tt>, after which pressing <tt>\tt</tt> (where <tt>\</tt> is your leader key)
 +
will save and compile the file.
  
 
You may customize the path to the <tt>mtxrun</tt> executable by setting <tt>g:context_mtxrun</tt>.
 
You may customize the path to the <tt>mtxrun</tt> executable by setting <tt>g:context_mtxrun</tt>.
Line 92: Line 59:
 
  let g:context_mtxrun = 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxrun'
 
  let g:context_mtxrun = 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxrun'
  
You may decide whether to use synctex or not by setting the <tt>g:context_synctex</tt> flag to <tt>1</tt> or <tt>0</tt>,
+
You may enable synctex by setting <tt>g:context_synctex</tt> to <tt>1</tt> (the default is <tt>0</tt>):
respectively. For example:
 
 
  let g:context_synctex = 1
 
  let g:context_synctex = 1
  
Line 102: Line 68:
 
command.
 
command.
  
Finally, for each of the above variables, a corresponding buffer-local variable with the same name may be defined,
+
Finally, for each of the above variables, a corresponding buffer-local variable with the same name
whose value takes precedence over the global value.
+
may be defined, whose value takes precedence over the global value.
  
 
=== Editing features ===
 
=== Editing features ===
Line 109: Line 75:
 
You may use the following commands to quickly jump to different parts of your document:
 
You may use the following commands to quickly jump to different parts of your document:
  
* <tt>[[</tt>: jump to the previous start of subject/section/chapter/part/component/product;
+
* <tt>[[</tt>: jump to the previous start of subject, section, chapter, part, component, or product;
* <tt>]]</tt>: jump to the next start of subject/section/chapter/part/component/product;
+
* <tt>]]</tt>: jump to the next start of subject, section, chapter, part, component, or product;
 
* <tt>[]</tt>: jump to the previous end of section, chapter, etc…;
 
* <tt>[]</tt>: jump to the previous end of section, chapter, etc…;
 
* <tt>][</tt>: jump to the next end of section, chapter, etc…;
 
* <tt>][</tt>: jump to the next end of section, chapter, etc…;
Line 127: Line 93:
  
 
So, for example, you may copy (“yank” in Vim's jargon) a paragraph by typing <tt>ytp</tt> (“yank a TeX
 
So, for example, you may copy (“yank” in Vim's jargon) a paragraph by typing <tt>ytp</tt> (“yank a TeX
paragraph“), delete it with <tt>dtp</tt>, select it with <tt>vtp</tt> and so on. In particular, you may reflow
+
paragraph“), delete it with <tt>dtp</tt>, select it with <tt>vtp</tt>, reflow it with <tt>gqtp</tt>, etc…
a paragraph with <tt>gqtp</tt> (see <tt>:help gq</tt>).
 
 
Similarly, you may yank a formula with <tt>vi$</tt> (or <tt>va$</tt>), and delete it, select it, etc…, in a
 
Similarly, you may yank a formula with <tt>vi$</tt> (or <tt>va$</tt>), and delete it, select it, etc…, in a
 
similar fashion.
 
similar fashion.
Line 148: Line 113:
 
Most of the features of such filetypes work also inside ConTeXt's MetaPost environments,
 
Most of the features of such filetypes work also inside ConTeXt's MetaPost environments,
 
such as <tt>\startMPpage… \stopMPpage</tt>.
 
such as <tt>\startMPpage… \stopMPpage</tt>.
 +
 
In particular, Vim automatically highlights and indents MetaPost and MetaFun code inside a ConTeXt document.
 
In particular, Vim automatically highlights and indents MetaPost and MetaFun code inside a ConTeXt document.
 
Besides, when you are inside a MetaPost environment, you may press CTRL-X followed by CTRL-O
 
Besides, when you are inside a MetaPost environment, you may press CTRL-X followed by CTRL-O
Line 163: Line 129:
 
The key is the name of the filetype and the corresponding value is name of the command.
 
The key is the name of the filetype and the corresponding value is name of the command.
  
 +
=== TODO ===
 +
 +
* Extract data from texweb and create syntax highlighting definitions for ConTeXt.
 +
* Some essential math support.
 +
* Proper URL highlighting ('%' doesn't start a comment, ...) [request by VnPenguin].
 +
* Perhaps borrow something from http://vim-latex.sourceforge.net/?
  
 
== Other useful vim plugins ==
 
== Other useful vim plugins ==
  
* autocomplete: http://vim.sourceforge.net/scripts/script.php?script_id=182, almost undocumented, but life-saving
+
=== Autocompletion ===
* spell-checker: http://www.vim.org/scripts/script.php?script_id=499, but native spell-checking support is included in Vim 7 (see above).
 
  
=== TODO ===
+
Vim offers a good completion mechanism (<tt>:help ins-completion</tt>), but there are several plugins
 +
that improves on it, in particular, to provide automatic completion of keywords:
 +
 
 +
* µcomplete: https://github.com/lifepillar/vim-mucomplete
 +
* Completor: https://github.com/maralla/completor.vim
 +
* NeoComplete: https://github.com/Shougo/neocomplete.vim
 +
* Deoplete (for NeoVim): https://github.com/Shougo/deoplete.nvim
 +
* YouCompleteMe: https://github.com/Valloric/YouCompleteMe
 +
* AutoComplPop: https://github.com/vim-scripts/AutoComplPop
 +
* SuperTab: https://github.com/ervandew/supertab
 +
 
 +
== A note on filetype detection ==
 +
 
 +
TeX (Plain TeX), LaTex and ConTeXt all use the <tt>.tex</tt> extension for files, which makes it difficult to detect the filetype based on the extension. From Vim 7 onwards, Vim does some intelligent checking to see it the file is <tt>plaintex</tt> or <tt>latex</tt> or <tt>context</tt>.
 +
 
 +
If the first line of a <tt>*.tex</tt> file has the form
 +
%&<format>
 +
then this determines the file type:  <tt>plaintex</tt> (for Plain TeX), <tt>context</tt> (for
 +
ConTeXt), or <tt>tex</tt> (for LaTeX).  Otherwise, the file is searched for keywords to
 +
choose <tt>context</tt> or <tt>tex</tt>.  If no keywords are found, it defaults to <tt>plaintex</tt>.
 +
You can change the default by defining the variable <tt>g:tex_flavor</tt> to the format
 +
(not the file type) you use most.  Use one of these:
 +
let g:tex_flavor = "plain"
 +
let g:tex_flavor = "context"
 +
let g:tex_flavor = "latex"
 +
Currently no other formats are recognized.
 +
 
 +
* If you use ConTeXt most of the time, but occasionally use LaTeX or Plain TeX, you can add the following to your <tt>.vimrc</tt>
 +
let g:tex_flavor = "context"
 +
* If you only use ConTeXt, you can add the following lines to <tt>filetype.vim</tt>:
 +
" ConTeXt
 +
augroup filetypedetect
 +
au! BufRead,BufNewFile *.tex setfiletype context
 +
augroup END
 +
so the next time you open a <tt>*.tex</tt> file, Vim will always recognize it as a ConTeXt document.
  
* extract data from texweb and create syntax highlighting definitions for ConTeXt
+
== A note on spell checking ==
* some essential math support
+
 
* proper URL highlighting ('%' doesn't start a comment, ...) [request by VnPenguin]
+
Vim 7 or later has a built-in spell checker. To enable it or disable it, use:
* perhaps borrow something from http://vim-latex.sourceforge.net/?
+
:set spell
 +
or
 +
:set nospell
 +
respectively.
 +
To set the language to be used for spell checking, set the <tt>spelllang</tt> option accordingly. For example:
 +
:set spelllang=en_us
 +
Use lowercase letters (<tt>en_us</tt>, not <tt>en_US</tt>). When you set <tt>spelllang</tt>, Vim offers to
 +
download the language data into your <tt>.vim</tt> folder, if such language is not available.
 +
You can put the above settings in your <tt>.vimrc</tt> if you like.
  
 
== using latex-suite ==
 
== using latex-suite ==
Line 201: Line 214:
  
 
== Powerful key mappings ==
 
== Powerful key mappings ==
 +
 +
It is useful to add mappings for these commands. For example:
 +
  nnoremap <silent> ]q :<c-u><c-r>=v:count1<cr>cnext<cr>zz
 +
  nnoremap <silent> [q :<c-u><c-r>=v:count1<cr>cprevious<cr>zz
 +
Or install Tim Pope's <i>unimpaired</i> plugin.
  
 
a set of buffer-local insert-mode macros to speed up ConTeXt source editing (by [[User:David antos|D.A.]] 19:52, 8 Jul 2005 (CEST))
 
a set of buffer-local insert-mode macros to speed up ConTeXt source editing (by [[User:David antos|D.A.]] 19:52, 8 Jul 2005 (CEST))

Revision as of 17:01, 30 October 2016

< Text Editors | Related Programs >

http://www.vim.org/

This page is about editing ConTeXt source in Vim, gVim, MacVim, NeoVim, and other Vim clones. The page describes the scripts available with Vim v8.0.0047 or later. If you are using an older Vim, you may copy the scripts from Vim's distribution (https://github.com/vim/vim), under the runtime directory. Everything should work, at least with Vim 7.4.

Using ConTeXt in Vim

Nikolai Weibull was the first one who wrote context.vim files and submitted them to the official Vim repository. They are part of the official Vim 7, and were expanded and improved in Vim 8.

If you feel that something is missing, please contribute!

Information about providing feedback is in the header of the scripts.

Typesetting

The recommended way to typeset a ConTeXt document is to use the :ConTeXt command. Just type:

:ConTeXt

to typeset the document in the current buffer. Typesetting happens in the background if you are using Vim 8.0.0047 or later, so you may continue working on your document. If there are errors, the quickfix window opens automatically to show the errors (one per line). The cursor stays in the main document, so your typing workflow is not disrupted. You may use standard quickfix commands to jump between errors: :cfirst, :cprev, :cnext, etc… (see :help quickfix). See below for useful mappings for these commands.

If your document is typeset without errors, Success! is printed at the bottom of the screen.

The :ConTeXt command accepts an optional path, in case you want to typeset a document different from the current one (useful for big projects).

You may check the status of your ConTeXt jobs with :ConTeXtJobStatus, and you may stop all running jobs with :ConTeXtStopJobs (these commands are available only in Vim 8.0.0047 or later).

An alternative way to typeset a document is to use :make. Set the current working directory to the directory of the current buffer, then execute :make:

lcd /path/to/my/project
:make

If a Makefile exists in the working directory, it is used (see below for a sample Makefile). You may let g:context_ignore_makefile=1 to ignore an existing Makefile. If no Makefile is found, mtxrun will be invoked directly. Note that :make always performs synchronous typesetting. Also, if there are errors, the quickfix list is populated, but you have open it manually with :copen.

It is recommended that you map the above commands. For example, you may add

 nnoremap <silent> <leader>tt :<c-u>update<cr>:ConTeXt<cr>

to your .vimrc, or (better)

 nnoremap <buffer> <silent> <leader>tt :<c-u>update<cr>:ConTeXt<cr>

to ~/.vim/after/ftplugin/context.vim, after which pressing \tt (where \ is your leader key) will save and compile the file.

You may customize the path to the mtxrun executable by setting g:context_mtxrun. For example, if you want to use your ConTeXt Beta installation at ~/Applications/ConTeXt-Beta, and you are using macOS, you may set the variable as follows:

let g:context_mtxrun = 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxrun'

You may enable synctex by setting g:context_synctex to 1 (the default is 0):

let g:context_synctex = 1

You may pass mtxrun additional options by putting them in g:context_extra_options. For example:

let g:context_extra_options = '--arrange --autopdf'

The --autogenerate, --nonstopmode and --synctex options are always included in the command.

Finally, for each of the above variables, a corresponding buffer-local variable with the same name may be defined, whose value takes precedence over the global value.

Editing features

You may use the following commands to quickly jump to different parts of your document:

  • [[: jump to the previous start of subject, section, chapter, part, component, or product;
  • ]]: jump to the next start of subject, section, chapter, part, component, or product;
  • []: jump to the previous end of section, chapter, etc…;
  • ][: jump to the next end of section, chapter, etc…;
  • [{: jump to the previous \start… or \setup… command;
  • ]}: jump to the next \stop… or /setup… command;

Each of the above accepts an optional count. For example, you may type 3[{ to jump three \start… commands before.

You may use the following ConTeXt-specific text objects, to be used in Visual or Operator-pending mode (see :help text-objects):

  • i$: inside $…$ (dollars excluded);
  • a$: around $…$ (dollars included);
  • tp: a ConTeXt paragraph.

So, for example, you may copy (“yank” in Vim's jargon) a paragraph by typing ytp (“yank a TeX paragraph“), delete it with dtp, select it with vtp, reflow it with gqtp, etc… Similarly, you may yank a formula with vi$ (or va$), and delete it, select it, etc…, in a similar fashion.

If you have enabled the matchit plugin included in Vim (see :help matchit), you may also type % to jump between the start and the stop of a command, or between parentheses.

You may jump to a different file by positioning the cursor over the file name and typing gf (:help gf). For example, if you have the following in your document:

\component my_component

putting the cursor over my_component and pressing gf will open my_component.tex.

Vim searches for files in the locations specified by the path option (this is a Vim feature). You may likely have to change the value of path for the above to work.

Integration with MetaPost

Vim offers excellent support for editing METAFONT and MetaPost documents (mf and mp filetypes). Most of the features of such filetypes work also inside ConTeXt's MetaPost environments, such as \startMPpage… \stopMPpage.

In particular, Vim automatically highlights and indents MetaPost and MetaFun code inside a ConTeXt document. Besides, when you are inside a MetaPost environment, you may press CTRL-X followed by CTRL-O to complete a MetaPost/MetaFun keyword. This works out of the box: no configuration is required.

Integration with other languages

Lua syntax highlighting is used inside \directlua{} and \ctxlua{} commands, and inside \startluacode… \stopluacode. XML highlighting is used inside \startXML… \stopXML.

You may embed other filetypes. Just define g:context_include (or b:context_include for buffer-specific settings). For example, if you want to highlight C++ code inside, say, \startCPP… \stopCPP, define:

let g:context_include = { 'cpp' : 'CPP' }

The key is the name of the filetype and the corresponding value is name of the command.

TODO

  • Extract data from texweb and create syntax highlighting definitions for ConTeXt.
  • Some essential math support.
  • Proper URL highlighting ('%' doesn't start a comment, ...) [request by VnPenguin].
  • Perhaps borrow something from http://vim-latex.sourceforge.net/?

Other useful vim plugins

Autocompletion

Vim offers a good completion mechanism (:help ins-completion), but there are several plugins that improves on it, in particular, to provide automatic completion of keywords:

A note on filetype detection

TeX (Plain TeX), LaTex and ConTeXt all use the .tex extension for files, which makes it difficult to detect the filetype based on the extension. From Vim 7 onwards, Vim does some intelligent checking to see it the file is plaintex or latex or context.

If the first line of a *.tex file has the form

%&<format>

then this determines the file type: plaintex (for Plain TeX), context (for ConTeXt), or tex (for LaTeX). Otherwise, the file is searched for keywords to choose context or tex. If no keywords are found, it defaults to plaintex. You can change the default by defining the variable g:tex_flavor to the format (not the file type) you use most. Use one of these:

let g:tex_flavor = "plain"
let g:tex_flavor = "context"
let g:tex_flavor = "latex"

Currently no other formats are recognized.

  • If you use ConTeXt most of the time, but occasionally use LaTeX or Plain TeX, you can add the following to your .vimrc
let g:tex_flavor = "context"
  • If you only use ConTeXt, you can add the following lines to filetype.vim:
" ConTeXt
augroup filetypedetect
	au! BufRead,BufNewFile *.tex		setfiletype context
augroup END

so the next time you open a *.tex file, Vim will always recognize it as a ConTeXt document.

A note on spell checking

Vim 7 or later has a built-in spell checker. To enable it or disable it, use:

:set spell

or

:set nospell

respectively. To set the language to be used for spell checking, set the spelllang option accordingly. For example:

:set spelllang=en_us

Use lowercase letters (en_us, not en_US). When you set spelllang, Vim offers to download the language data into your .vim folder, if such language is not available. You can put the above settings in your .vimrc if you like.

using latex-suite

latex-suite currently doesn't support ConTeXt, but if you use it, here's what you have to do to compile ConTeXt documents:

1. After downloading and installing latex-suite, locate the file "texrc" (usually located in ~/.vim/ftplugin/latex-suite). Copy this file to ~/.vim/ftplugin/tex/texrc

2. Open this copy in your favorite editor (vim comes to mind...)

3. After line 80 in this file, there is a series of "Compiler rules." Just add this line to the section:

TexLet g:Tex_CompileRule_cont = 'texexec --pdf --nonstopmode $*'

This will add compilation for ConTeXT. In order to use it:

4. When you're in vim normal mode, run this command:

TGTarget cont [that's "colon TGTarger cont"] 

5. Edit your TeX-files, save the changes; when you want to compile, switch to normal mode and just type \ll (that's 'backslash el el' )

Voila, compilation should start. You'll have to specify this compiler target every timeI you open a TeX-file in Vim. If you want to make this the default compiler, you should have this line in your texrc:

TexLet g:Tex_DefaultTargetFormat = 'cont' 

Powerful key mappings

It is useful to add mappings for these commands. For example:

 nnoremap <silent> ]q :<c-u><c-r>=v:count1<cr>cnext<cr>zz
 nnoremap <silent> [q :<c-u><c-r>=v:count1<cr>cprevious<cr>zz

Or install Tim Pope's unimpaired plugin.

a set of buffer-local insert-mode macros to speed up ConTeXt source editing (by D.A. 19:52, 8 Jul 2005 (CEST))

  • I have remapped <leader> to comma (one hardly ever use commas just before a letter)
  • two types of mappings: stand-alone and changing the previous word
  • usage of mappings that change the previous word: type the name of the macro and ,ta (for tag, use your leader character instead of the comma); it created \start-\stop block of the macro
  • put the code into .vim/after/plugin/context.vim
let maplocalleader = mapleader

" Make start-stop block out of the previous word
imap <buffer> <LocalLeader>ta \start<Cr>\stop<Cr><Esc>4bhdiw$pj$pO
imap <buffer> <LocalLeader>tb \begin<Cr>\end<Cr><Esc>4bhdiw$pj$pO

" Itemize
imap <buffer> <LocalLeader>it \startitemize<Cr>\stopitemize<Esc>O\item<Space>
imap <buffer> <LocalLeader>en \startitemize[n]<Cr>\stopitemize<Esc>O\item<Space>
imap <buffer> <LocalLeader>i<Return> \item<Space>

" Font switching and emphasize
imap <buffer> <LocalLeader>em {\em }<Left>
imap <buffer> <LocalLeader>sc {\sc }<Left>

" Define... and setup...
imap <buffer> <LocalLeader>de \define
imap <buffer> <LocalLeader>se \setup

" Typing and type
imap <buffer> <LocalLeader>ty \type{}<Left>
imap <buffer> <LocalLeader>typ typing<LocalLeader>ta

" Quote and quotation
imap <buffer> <LocalLeader>" \quotation{}<Left>
imap <buffer> <LocalLeader>' \quote{}<Left>

key mappings borrowed from scite

If you use the stand-alone distribution for windows/Linux.You can reset the key mapping to speed ConTeXt compiling.

just add the following code to your _vimrc(or .vimrc file under Linux) file:

"run setup and complie, then open the result pdf file
 map <F5> <Esc><Esc>:sil ! "D:\context\tex\setuptex.bat && texmfstart texexec.pl --autopdf --pdf '%'"<CR><CR>

"view the corresponding pdf file
map <F6> <Esc><Esc>:sil ! D:\"Program Files"\Adobe\Acrobat\Acrobat.exe %:p:r.pdf<CR><CR>

"run setup and make purge
map <F7> <Esc><Esc>:sil ! "D:\context\tex\setuptex.bat && texmfstart texutil.pl --purge"<CR><CR>

"run setup and make list of the current file
map <F8> <Esc><Esc>:sil ! "D:\context\tex\setuptex.bat && texmfstart texexec.pl --autopdf --pdf --list --result=%:p:r_list %"<CR><CR>

Makefile

For your ConTeXt document, you can prepare a Makefile like this one (Contributed by Buggs):

# An example Makefile to compile a context file, paper.tex
paper.pdf: paper.tex
    texexec paper

test:
    xpdf paper.pdf

clean:
    rm *.bbl *.dvi *.aux *.log *.blg

If you put these mappings to your .vimrc file, you can than compile the document with F9 and preview it with F8:

" map ":make" to the F9 key
imap <F9> <ESC>:make<CR>
nmap <F9> :make<CR>

"map ":make test" to the F8 key
imap <F8> <ESC>:make test<CR>
nmap <F8> :make test<CR>