Changes

Jump to navigation Jump to search
2,666 bytes added ,  11:01, 2 July 2020
m
drop dup title and navbox
< [[Text Editors]] | [[Related Programs]] >
http://www.vim.org/
An alternative way to typeset a document is to use <tt>:make</tt>. Set the current working
directory to the directory of the current buffer, then execute <tt>:make</tt>:
:lcd /path/to/my/project
:make
If a <tt>Makefile</tt> exists in the working directory, it is used (see below for a sample 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 are
errors, 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 <silent> <leader>tt :<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)
let g:context_mtxrun = 'PATH=$HOME/Applications/ConTeXt-Beta/tex/texmf-osx-64/bin:$PATH mtxrun'
You may To enable synctex by setting <tt>g:context_synctex</tt> to disable SyncTeX, use <tt>1\setupsynctex[state=start]</tt> (the default is and <tt>0\setupsynctex[state=stop]</tt>): let g:context_synctex = 1, respectively, in your document.
You may pass <tt>mtxrun</tt> additional options by putting them in <tt>g:context_extra_options</tt>.
For example:
let g:context_extra_options = '--arrange --autopdf'
The <tt>--autogenerate</tt>, and <tt>--nonstopmode</tt> and <tt>--synctex</tt> options are always included in the
command.
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>:
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.
== Powerful key mappings ==
the prefix for user-defined mappings.
By default, the leader is the backslash character, but that may be changed by the user.
For example, to use a comma as a leader, put this in your <tt>.vimrc</tt>:
map <leader> ,
Rather than overriding the default leader, you may define an alternative key. The <tt><space></tt> is a good
choice, because by default it has the same function as the <tt><right></tt> key, and it is comfortable to type:
map <space> <leader> " Use <space> as an alternative leader (backslash can still be used)
 
=== Clean up auxiliary files ===
 
The following function can be used to clean up temporary files:
fun! ConTeXtClean()
let l:currdir = expand("%:p:h")
let l:tmpdirs = ['out'] " Temporary directories
let l:suffixes = ['aux', 'bbl', 'blg', 'fls', 'log', 'tuc'] " Suffixes of temporary files
for ff in glob(l:currdir . '/*.{' . join(l:suffixes, ',') . '}', 1, 1)
call delete(ff)
endfor
for dd in l:tmpdirs
let l:subdir = l:currdir . '/' . dd
if isdirectory(l:subdir)
for ff in glob(l:subdir . '/*.{' . join(l:suffixes, ',') . '}', 1, 1)
call delete(ff)
endfor
endif
call delete(l:subdir) " Delete directory (only if empty)
endfor
echomsg "Aux files removed"
endf
Customize <tt>l:tmpdirs</tt> and <tt>l:suffixes</tt> to suit your needs.
In Windows systems, you may have to replace each slash with a backslash, too.
 
The following mapping allows you to remove auxiliary files by pressing <tt>\tc</tt>:
nnoremap <silent><buffer> <leader>tc :<c-u>call ConTeXtClean()<cr>
 
=== Snippets ===
 
Vim allows you to define abbreviations for frequently used pieces of text (see <tt>:help abbreviations</tt>).
Here are a few examples:
<pre>
fun! Eatchar(pat) " See :help abbreviations
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfun
 
iab <buffer> ch- \startchapter[title={<c-o>ma}]<cr><c-o>mb<cr>\stopchapter<esc>`a`b<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<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<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<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<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<c-o>a<c-r>=Eatchar('\s')<cr>
iab <buffer> item- \startitemize<cr><cr>\stopitemize<up><tab>\item
iab <buffer> enum- \startitemize[n]<cr><cr>\stopitemize<up><tab>\item
iab <buffer> i- \item
</pre>
 
Type the abbreviation followed by Space to expand the snippet, then continue typing normally.
 
Inside the definition of an abbreviation, marks may be set (see <tt>:h m</tt>), which allow you to jump between the different
parts of a snippet with TAB (CTRL-i) and CTRL-O (in Normal mode) after the abbreviation is expanded (see <tt>:h jump-motions</tt>).
For example, after typing <tt>ch- </tt>, the cursor will be at the title's position. If you press <tt><esc><tab></tt> (or
<tt><c-o><tab></tt> if you want to stay in Insert mode after the jump), you will jump between <tt>\startchapter</tt>
and <tt>\stopchapter</tt>.
=== 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>
nnoremap <silent> [q :<c-u><c-r>=v:count1<cr>cprevious<cr>zz
nnoremap <silent> ]Q :<c-u>clast<cr>zz
nnoremap <silent> [Q :<c-u>cpreviouscfirst<cr>zz
Or install Tim Pope's <i>unimpaired</i> plugin.
rm *.aux *.bbl *.blg *.log *.tuc
If you put these mappings to your <code>.vimrc</code> file, you can then compile the document with F9 and preview it with F8:
" map ":make" to the F9 key
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.
=== Snippets UltiSnips ===
Vim allows you to define abbreviations for frequently used pieces of text (see <tt>:help abbreviations</tt>).If you need more sophisticated support for snippets of code, UltiSnips[https://github.com/SirVer/ultisnips]is the plugin to usea sophisticated snippets manager. Here are a few examples of useful UltiSnips snippets for ConTeXt:
snippet "s(tart)?" "start / stop" br
TexLet g:Tex_DefaultTargetFormat = 'cont'
{{Installation navbox}}
[[Category:Text Editors]]

Navigation menu