Changes

Jump to navigation Jump to search
275 bytes added ,  06:57, 31 July 2023
m
httphttps://www.vim.org/
This page is about editing ConTeXt source in Vim, gVim, MacVim, and other Vim clones.
Nikolai Weibull was the first one who wrote <tt>context.vim</tt> 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. Starting with Vim 9.0.0218, the scripts supporting ConTeXt in Vim have been rewritten in Vim 9 script and they can be integrated with (the new Vim's scripting language). For the syntax files generated by complete documentation, see <tt>mtxrun:help ft-context</tt>. You may add the additional syntax files as follows:  mkdir -p ~/.vim/syntax/shared cd ~/.vim/syntax/shared mtxrun --script interface --vim The above assumes that your Vim configuration is in the `~/.vim` directory, of course. Adding those files is not mandatory, but they will add lots of keywords for auto-completion and will improve the syntax coloring for MetaFun code.
=== Asciicast ===
The recommended way to typeset a ConTeXt document is to use the <tt>:ConTeXt</tt> command. Just type:
:ConTeXt%
to compile the document in the current buffer.
Typesetting happens in the background,
so you may continue working on your document. If there are errors, the quickfix window opens will open automaticallyto show the errors (one per line). The cursor stays will stay in the main document, so your typing workflow is will notbe 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>). See below for useful mappings for these commands.
running jobs with <tt>:ConTeXtStopJobs</tt>.
An alternative way to typeset === Setting a document is to use <tt>:make</tt>. Set the current workingdirectory to the directory of the current buffer, then execute <tt>:make</tt>: :lcd /path/to/my/project :makeIf a <tt>Makefile</tt> exists in the working directory, it is used (see below for a sample Makefile).You may <tt>let g:context_ignore_makefilecustom typesetting engine ===1</tt> to ignore an existing Makefile.If no Makefile is found, <tt>mtxrun</tt> will be invoked directly.Note that <tt>:make</tt> always performs synchronous typesetting. Also, if there areerrors, the quickfix list is populated, but you have to open it manually with <tt>:copen</tt>.
It is recommended that you map the above commands. For example, you may add nnoremap The <silenttt> :ConTeXt<leader>/tt :<c-u>updatecommand invokes the <crtt>:ConTeXtmtxrun<cr/tt>to your script that is found in <tt>vimrc$PATH</tt>. For more fine grained control over the command and its environment, you may invoke `context.Typeset()` directly (or `context#Typeset(better) nnoremap ` from legacy Vim script). For instance, if you have installed a version of ConTeXt in <buffertt> $HOME/context<silent/tt> (where <leader>tt :<c-u>update$HOME<cr/tt>:ConTeXt<cr>is the path to your home directory), you may define a function to use it similar to the following (you may put the following code in <tt>~/.vim/after/ftplugin/context.vim</tt>, after which pressing <tt>\tt</tt> (where <tt>\</tt> is your leader key)will save creating the file and compile the file.directories if they do not exist):
You may customize the path to the <tt>mtxrun</tt> executable by setting <tt>g:context_mtxrun</tt>.For example, if you want to use your ConTeXt Beta installation at <tt>~/Applications/ConTeXt-Beta</tt>,and you are using macOS, you may set the variable as follows: let g:context_mtxrun = import autoload 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxruncontext.vim'
To enable def MyConTeXt() const env = {'PATH': printf("%s/context/tex/disable SyncTeX, use <tt>\setupsynctex[state=start]texmf-</ttos> and -<ttarch>\setupsynctex[state=stop]</tt>bin:%s", respectively$HOME, in your document$PATH)} context.Typeset("%", env) enddef
You may pass and perhaps use it with a mapping:  nnoremap <silent><buffer><leader>t <ttscriptcmd>mtxrunMyConTeXt()</ttcr> additional options by putting them in  <tt>g:context_extra_optionscontext.Typeset()</tt>accepts a third optional argument to specify a customtypesetting command.That must be a function that takes a path and returns thecommand as a List. For example:  let gdef ConTeXtCustomCommand(path:context_extra_options = string): list<string> return ['mtxrun', '--arrange script', 'context', '--autopdfnonstopmode', path] enddef The context.ConTeXtTypeset("%", v:none, ConTeXtCustomCommand) === Working with large projects === Large projects are often organized as a root document and various chapterfiles. When editing a chapter file, it is convenient to invoke <tt>--autogenerate:ConTeXt</tt> and directly on it, rather than having to switch to the root file. A “magic line”can be added at the beginning of each chapter file, which specifies therelative path to the root file. For instance:  % !TEX root = ../MyRoot.tex Vim searches for the magic line in the first ten lines of the current buffer:if the magic line is found, the document specified by that line is typeset rather than theone in the current buffer. The root document does not have to be opened inVim. === Updating the syntax files === Vim includes syntax files generated by <tt>mtxrun</tt>. If you want to use more up-to-nonstopmodedate files, overriding those distributed with Vim, you may proceed as follows. Assuming your Vim configuration lives in <tt>~/.vim</tt> options are always included in the, you may type:  mkdir -p ~/.vim/syntax/shared cd ~/.vim/syntax/shared mtxrun --script interface --vim The last command.will create the following syntax files:
Finally, for each of the above variables, a corresponding buffer* <tt>context-local variable with the same namedata-context.vim</tt>;may be defined, whose value takes precedence over the global value* <tt>context-data-interfaces.vim</tt>;* <tt>context-data-metafun.vim</tt>;* <tt>context-data-tex.vim</tt>.
=== Editing features ===
Vim offers excellent support for editing METAFONT and MetaPost documents (<tt>mf</tt> and <tt>mp</tt> filetypes).
See <tt>:help ft-metapost</tt> for the details.
Most of the features of such filetypes work also inside ConTeXt's MetaPost environments,
such as <tt>\startMPpage… \stopMPpage</tt>.
=== 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].
imap <F8> <ESC>:exe "lcd" fnameescape(expand("%:p:h"))<CR>:make test<CR>
nmap <F8> :exe "lcd" fnameescape(expand("%:p:h"))<CR>:make test<CR>
 
Note that if you use <tt>:make</tt> typesetting will happen synchronously.
== Other useful Vim plugins ==

Navigation menu