Changes

Jump to navigation Jump to search
838 bytes added ,  06:57, 31 July 2023
m
< [[Text Editors]] | [[Related Programs]] >
httphttps://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 in Vim v8.0.0055 or later. If you are using Vim 7, see
''Using the scripts with an older Vim'' below.
 
<b>If you feel that something is missing, please contribute!</b>
 
Information about providing feedback is in the header of the scripts.
== Using ConTeXt in Vim ==
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 (the new Vim's scripting language). For the complete documentation, see <btt>If you feel that something is missing, please contribute!:help ft-context</bttInformation about providing feedback is in the header of the scripts.
=== 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 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 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.
You may check the status of your ConTeXt jobs with <tt>:ConTeXtJobStatus</tt>, and you may stop all
running jobs with <tt>:ConTeXtStopJobs</tt>. === Setting a custom typesetting engine === The <tt>:ConTeXt</tt> command invokes the <tt>mtxrun</tt> script that is found in <tt>$PATH</tt>. For more fine grained control over the command and its environment, you may invoke `context.Typeset()` directly (or `context#Typeset()` from legacy Vim script). For instance, if you have installed a version of ConTeXt in <tt>$HOME/context</tt> (these commands are available only where <tt>$HOME</tt> 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 Vim 8<tt>~/.0vim/after/ftplugin/context.0047 or latervim</tt>, creating the file and the directories if they do not exist):  import autoload 'context.vim'
An alternative way to typeset a document is to use <tt>:make</tt>. Set the current working def MyConTeXt()directory to the directory of the current buffer, then execute <tt> const env = {'PATH':make</tt>: lcd printf("%s/pathcontext/totex/my/project :makeIf a texmf-<ttos>Makefile-<arch>/tt> exists in the working directorybin:%s", $HOME, it is used (see below for a sample Makefile$PATH).}You may <tt>let g:context_ignore_makefile=1</tt> to ignore an existing Makefile context.If no Makefile is foundTypeset("%", <tt>mtxrun</tt> will be invoked directly.env)Note that <tt>:make</tt> always performs synchronous typesetting. Also, if there areerrors, the quickfix list is populated, but you have open it manually with <tt>:copen</tt>. enddef
It is recommended that you map the above commands. For example, you may add nnoremap <silent> <leader>tt and perhaps use it with a mapping:<c-u>update<cr>:ConTeXt<cr>to your <tt>vimrc</tt>, or (better) 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 and compile the file.
You may customize the path to the <tt>mtxrun nnoremap </ttsilent> executable by setting <ttbuffer>g:context_mtxrun</ttleader>.For example, if you want to use your ConTeXt Beta installation at t <ttscriptcmd>~/Applications/ConTeXt-BetaMyConTeXt()</ttcr>,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 <tt>g:context_synctexcontext.Typeset()</tt> accepts a third optional argument to <tt>1</tt> (specify a customtypesetting command. That must be a function that takes a path and returns the default is <tt>0</tt>): let gcommand as a List. For example:context_synctex = 1
You may pass def ConTeXtCustomCommand(path: string): list<ttstring> return ['mtxrun</tt> additional options by putting them in ', '--script', 'context', '--nonstopmode', path] enddef  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>g:context_extra_optionsConTeXt</tt>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 exampleinstancelet g% !TEX root = ../MyRoot.tex Vim searches for the magic line in the first ten lines of the current buffer:context_extra_options 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 == '--arrange --autopdf'= The Vim includes syntax files generated by <tt>--autogeneratemtxrun</tt>. If you want to use more up-to-date files, overriding those distributed with Vim, you may proceed as follows. Assuming your Vim configuration lives in <tt>--nonstopmode~/.vim</tt> and <tt>, you may type:  mkdir -p ~/.vim/syntax/shared cd ~/.vim/syntax/shared mtxrun --script interface --synctex</tt> options are always included in thevim 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>.
runtime/indent/{context,mf,mp}.vim
runtime/syntax/{context,mf,mp}.vim
 
<b>Note:</b> the runtime scripts in Vim 9.0.0218 or later are written in Vim 9 script (the new scripting language embedded in Vim) and there is no guarantee that they will work with older versions of Vim!
If you get the following error when you open a ConTeXt or MetaPost document:
=== 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].
Here are a few examples:
<pre>
fun! Eatchar(pat) " See :help abbreviations let c = nr2char(getchar(0)) return (c =~ a:pat) ? '' : cendfun iab <buffer> ch. - \startchapter[title={<c-o>ma}]<cr><c-o>mb<cr>\stopchapter<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> s. - \startsection[title={<c-o>ma}]<cr><c-o>mb<cr>\stopsection<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> ss. - \startsubsection[title={<c-o>ma}]<cr><c-o>mb<cr>\stopsubsection<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> sss. - \startsubsubsection[title={<c-o>ma}]<cr><c-o>mb<cr>\stopsubsubsection<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> slide. - \startslide[title={<c-o>ma}]<cr><c-o>mb<cr>\stopslide<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> fig. - \startplacefigure<cr><tab>\externalfigure[<c-o>ma]%<cr>[]<c-o>mb<cr><c-d>\stopplacefigure<esc>`a`b`aa<c-o>a<c-r>=Eatchar('\s')<cr>iab <buffer> item. - \startitemize<cr><cr>\stopitemize<up><tab>\itemiab <buffer> enum. - \startitemize[n]<cr><cr>\stopitemize<up><tab>\itemiab <buffer> i. - \item
</pre>
Type the abbreviation followed by CTRL-] Space to expand the snippet, thencontinue typing normally.Abbreviations may be triggered by any other non-keyword character (different from CTRL-]),but in that case such character is inserted in the text. Try, for example, <tt>i.</tt> followed by CTRL-]and followed by Enter, to see the difference.
Inside the definition of an abbreviation, you marks may be set marks (see <tt>:h m</tt>), which allows allow you to jump between the differentparts of a snippet with TAB (CTRL-O i) and CTRL-I O (in Normal mode) when after the abbreviation is expanded (see <tt>:h jump-motions</tt>).For example, after typing <tt>ch.- </tt><c-]>, the cursor will be at the title's position. If you press <tt><esc><c-otab></tt> (or<tt><c-o><c-otab></tt> if you want to stay in Insert mode after the jump), you will jump between <tt>\startchapter</tt>and <tt>\stopchapter</tt>. You may use <tt><c-i></tt> (in Normal mode) to jump back, or <tt><c-o></tt> to jumpat the end of the snippet.
=== Buffer-local Insert-mode macros to speed up editing ===
You can reset the key mapping to speed ConTeXt compiling.
Just add the following code to your <tt>_vimrc</t>tt> (or <tt>.vimrc</tt> file under Linux) file:
<pre>
"run setup and complie, then open the result pdf file
"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>
 
</pre>
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 ==
that improve on it, in particular, to provide automatic completion of keywords:
* µcompleteMUcomplete[https://github.com/lifepillar/vim-mucomplete]* Coc [https://github.com/neoclide/coc.nvim].
* Completor[https://github.com/maralla/completor.vim]
* NeoComplete[https://github.com/Shougo/neocomplete.vim]
* SuperTab[https://github.com/ervandew/supertab]
In the asciicast at the top of this page µcomplete MUcomplete was used.
=== UltiSnips ===
TexLet g:Tex_DefaultTargetFormat = 'cont'
{{Installation navbox}}
[[Category:Text Editors]]

Navigation menu