function! MathAndLiquid() "" Define certain regions " Block math. Look for "$$[anything]$$" syn region math start=/\$\$/ end=/\$\$/ " inline math. Look for "$[not $][anything]$" syn match math_block '\$[^$].\{-}\$' " Liquid single line. Look for "{%[anything]%}" syn match liquid '{%.*%}' " Liquid multiline. Look for "{%[anything]%}[anything]{%[anything]%}" syn region highlight_block start='{% highlight .*%}' end='{%.*%}' " Fenced code blocks, used in GitHub Flavored Markdown (GFM) syn region highlight_block start='```' end='```' "" Actually highlight those regions. hi link math Statement hi link liquid Statement hi link highlight_block Function hi link math_block Function endfunction " Call everytime we open a Markdown file "autocmd BufRead,BufNewFile,BufEnter *.md,*.markdown call MathAndLiquid() " \vm 2 4\ " \begin{vmatrix} " <++> & <++> & <++> & <++> \\ " <++> & <++> & <++> & <++ > \\ " \end{vmatrix}<++> " function! Tex() let mark = '\' let sepr = ' ' let tags = {'vm': 'vmatrix', 'bm': 'bmatrix', 'mt': 'matrix', 'cs': 'cases', 'ad': 'aligned', 'al': 'align', 'ar': 'array'} let text = getline('.') let end = col('.') let start = strridx(text, mark, end) if start > -1 let params = strpart(text, start+1, end - start - 1) let params = split(params, sepr) let abbr = params[0] if strlen(abbr) == 0 || !has_key(tags, abbr) return endif let rc = params[1] if !(rc>0) return endif if len(params)>2 let cc = params[2] if !(cc>0) return endif else let cc = 1 end let prefix = repeat(' ', start) let thecols = [] let i = 0 while i < cc call add(thecols, '<++>') let i += 1 endwhile let columnsText = prefix . ' '. join(thecols, ' & ') . ' \\' let lines = [] let i = 0 while i < rc call add(lines, columnsText) let i += 1 endwhile call add(lines, prefix . '\end{' . tags[abbr] . '}<++>') let leftPart = strpart(text, 0, start) let rightPart = strpart(text, end) if strlen(rightPart) > 0 call add(lines, prefix . rightPart) endif call setline(line('.'), leftPart . '\begin{' . tags[abbr] . '}') call append(line('.'), lines) "call append(line('.'), lines) endif endfunction " autocmd FileType markdown inoremap :call Tex()a " Navigating with guides inoremap /<++>"_c4l vnoremap /<++>"_c4l map /<++>"_c4l nmap NERDCommenterToggle vmap NERDCommenterTogglegv " Markdown setup autocmd FileType markdown inoremap \cs \begin{cases}\end{cases}<++>F\i autocmd FileType markdown inoremap \fr \frac{<++>}{<++>}<++>F\i autocmd FileType markdown inoremap ` `$$`<++>F$i autocmd FileType markdown inoremap $ $$$$<++>kO autocmd FileType markdown inoremap \{ \{\}<++>F{a autocmd FileType markdown vnoremap b c__"__