Changes

Jump to navigation Jump to search
515 bytes added ,  17:01, 30 October 2016
no edit summary
http://www.vim.org/
This page is about editing ConTeXt source in Vim, gVim, MacVim, NeoVim, and other Vim clones. Some of The page describes the described features are scripts available only in with Vim v8.0.0047 or later: they will be noted below.  == A note on filetype detection == TeX (Plain TeX)If you are using an older Vim, LaTex and ConTeXt all use the <tt>.tex</tt> extension for files, which makes it difficult to detect you may copy the filetype based on the extension. From Vim 7 onwards, scripts from Vim does some intelligent checking to see it the file is <tt>plaintex</tt> or <tt>latex</tt> or <tt>context</tt>.'s distribution  If the first line of a <tt>*.tex</tt> file has the form %&<format>then this determines the file type(https: <tt>plaintex</tt> (for Plain TeX), <tt>context</tt> (forConTeXt), or <tt>tex</tt> (for LaTeX)github. Otherwise, the file is searched for keywords tochoose <tt>context<com/tt> or <tt>tex<vim/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 typevim) 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 under the following lines to <tt>filetype.vimruntime</tt>: " ConTeXt augroup filetypedetect au! BufRead,BufNewFile *.tex setfiletype context augroup ENDso the next time you open a <tt>*directory.tex</tt> fileEverything should work, Vim will always recognize it as a ConTeXt document. == A note on spell checking ==atleast with Vim 7 or later has a built-in spell checker. To enable it or disable it, use: :set spellor :set nospellrespectively.To set the language to be used for spell checking, set the <tt>spelllang</tt> option accordingly. For example: :set spelllang=en_usUse lowercase letters (<tt>en_us</tt>, not <tt>en_US</tt>). When you set <tt>spelllang</tt>, Vim offers todownload 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 like4.
== Using ConTeXt in Vim ==
The recommended way to typeset a ConTeXt document is to use the <tt>:ConTeXt</tt> 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 error 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>,
<tt>:cnext</tt>, etc… (see <tt>:help quickfix</tt>). It is See below for 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>zzOr 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.
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 Set the current workingdirectory is set to the path to directory of the file you want to compile (set with current buffer, then execute <tt>:lcd …make</tt>), and type: lcd /path/to/my/project
:make
If a <tt>Makefile</tt> is present exists in the working directory, it will be is used (you see below for a sample Makefile).You may<tt>let g:context_ignore_makefile=1</tt> to ignore it)an existing Makefile. OtherwiseIf no Makefile is found, <tt>mtxrun</tt> willbe 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>.
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 (if necessary) and compile the file.
You may customize the path to the <tt>mtxrun</tt> executable by setting <tt>g:context_mtxrun</tt>.
let g:context_mtxrun = 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxrun'
You may decide whether to use enable synctex or not by setting the <tt>g:context_synctex</tt> flag to <tt>1</tt> or (the default is <tt>0</tt>,respectively. For example):
let g:context_synctex = 1
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:
* <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/, or product;
* <tt>[]</tt>: jump to the previous end of section, chapter, etc…;
* <tt>][</tt>: jump to the next end of section, chapter, etc…;
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 reflowa paragraph it with <tt>gqtp</tt> (see <tt>:help gq</tt>)., etc…
Similarly, you may yank a formula with <tt>vi$</tt> (or <tt>va$</tt>), and delete it, select it, etc…, in a
similar fashion.
Most of the features of such filetypes work also inside ConTeXt's MetaPost environments,
such as <tt>\startMPpage… \stopMPpage</tt>.
 
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
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 ==
* autocomplete: http://vim.sourceforge.net/scripts/script.php?script_id=182, almost undocumented, but life-saving* spell-checker: http://www.vim.org/scripts/script.php?script_id=499, but native spell-checking support is included in Vim 7 (see above).= Autocompletion ===
Vim offers a good completion mechanism (<tt>:help ins-completion</tt>), but there are several pluginsthat 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 = TODO 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> (forConTeXt), or <tt>tex</tt> (for LaTeX). Otherwise, the file is searched for keywords tochoose <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 ENDso 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 Vim 7 or later has a commentbuilt-in spell checker. To enable it or disable it, use: :set spellor :set nospellrespectively.To set the language to be used for spell checking, set the <tt>spelllang</tt> option accordingly..) [request by VnPenguin]For example:* perhaps borrow something from http :set spelllang=en_usUse lowercase letters (<tt>en_us</tt>, not <tt>en_US</tt>). When you set <tt>spelllang</tt>, Vim offers todownload the language data into your <tt>.vim-latex</tt> folder, if such language is not available.sourceforgeYou can put the above settings in your <tt>.netvimrc</?tt> if you like.
== using latex-suite ==
== 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))
134

edits

Navigation menu