" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 " Vimwiki syntax file " Home: https://github.com/vimwiki/vimwiki/ " Quit if syntax file is already loaded if v:version < 600 syntax clear elseif exists('b:current_syntax') finish endif let s:current_syntax = vimwiki#vars#get_wikilocal('syntax') " Get config: possibly concealed chars let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : '' let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : '' " Populate all syntax vars " Include syntax/vimwiki_markdown.vim as "side effect" call vimwiki#vars#populate_syntax_vars(s:current_syntax) let syntax_dic = g:vimwiki_syntax_variables[s:current_syntax] " text: `code` or ``code`` only inline " Note: `\%(^\|[^`]\)\@<=` means after a new line or a non ` let syntax_dic.dTypeface.code = [ \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=', \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='], \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=', \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='], \ ] " text: ~~deleted text~~ let syntax_dic.dTypeface.del = ([ \ ['\~\~', '\~\~']]) " text: $ equation_inline $ " Match only one $ " ( ^ or not $) before $ and after: not $ let syntax_dic.dTypeface.eq = ([ \ ['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', \ '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']]) " text: ^superscript^ let syntax_dic.dTypeface.sup = ([ \ ['\^', '\^']]) " text: ,,subscript,, let syntax_dic.dTypeface.sub = ([ \ [',,', ',,']]) " LINKS: highlighting is complicated due to "nonexistent" links feature function! s:add_target_syntax_ON(target, type) abort let prefix0 = 'syntax match '.a:type.' `' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char' let prefix1 = 'syntax match '.a:type.'T `' let suffix1 = '` display contained' execute prefix0. a:target. suffix0 execute prefix1. a:target. suffix1 endfunction function! s:add_target_syntax_OFF(target) abort let prefix0 = 'syntax match VimwikiNoExistsLink `' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,VimwikiLinkChar' let prefix1 = 'syntax match VimwikiNoExistsLinkT `' let suffix1 = '` display contained' execute prefix0. a:target. suffix0 execute prefix1. a:target. suffix1 endfunction function! s:highlight_existing_links() abort " Wikilink " Conditional highlighting that depends on the existence of a wiki file or " directory is only available for *schemeless* wiki links " Links are set up upon BufEnter (see plugin/...) let safe_links = '\%('.vimwiki#base#file_pattern( \ vimwiki#vars#get_bufferlocal('existing_wikifiles')) . '\%(#[^|]*\)\?\|#[^|]*\)' " Wikilink Dirs set up upon BufEnter (see plugin/...) let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs')) " match [[URL]] let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')), \ safe_links, vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') " match [[URL|DESCRIPTION]] let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')), \ safe_links, vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') " match {{URL}} let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate1')), \ safe_links, vimwiki#vars#get_global('rxWikiInclArgs'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') " match {{URL|...}} let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate2')), \ safe_links, vimwiki#vars#get_global('rxWikiInclArgs'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') " match [[DIRURL]] let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')), \ safe_dirs, vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') " match [[DIRURL|DESCRIPTION]] let target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')), \ safe_dirs, vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(target, 'VimwikiLink') endfunction " use max highlighting - could be quite slow if there are too many wikifiles if vimwiki#vars#get_wikilocal('maxhi') " WikiLink call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink')) " WikiIncl call s:add_target_syntax_OFF(vimwiki#vars#get_global('rxWikiIncl')) " Subsequently, links verified on vimwiki's path are highlighted as existing call s:highlight_existing_links() else " Wikilink call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink'), 'VimwikiLink') " WikiIncl call s:add_target_syntax_ON(vimwiki#vars#get_global('rxWikiIncl'), 'VimwikiLink') endif " Weblink call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink'), 'VimwikiLink') " WikiLink " All remaining schemes are highlighted automatically let s:rxSchemes = '\%('. \ vimwiki#vars#get_global('schemes') . '\|'. \ vimwiki#vars#get_global('web_schemes1'). \ '\):' " a) match [[nonwiki-scheme-URL]] let s:target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')), \ s:rxSchemes.vimwiki#vars#get_global('rxWikiLinkUrl'), \ vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(s:target, 'VimwikiLink') " b) match [[nonwiki-scheme-URL|DESCRIPTION]] let s:target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')), \ s:rxSchemes.vimwiki#vars#get_global('rxWikiLinkUrl'), \ vimwiki#vars#get_global('rxWikiLinkDescr'), '', '') call s:add_target_syntax_ON(s:target, 'VimwikiLink') " a) match {{nonwiki-scheme-URL}} let s:target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate1')), \ s:rxSchemes.vimwiki#vars#get_global('rxWikiInclUrl'), \ vimwiki#vars#get_global('rxWikiInclArgs'), '', '') call s:add_target_syntax_ON(s:target, 'VimwikiLink') " b) match {{nonwiki-scheme-URL}[{...}]} let s:target = vimwiki#base#apply_template( \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate2')), \ s:rxSchemes.vimwiki#vars#get_global('rxWikiInclUrl'), \ vimwiki#vars#get_global('rxWikiInclArgs'), '', '') call s:add_target_syntax_ON(s:target, 'VimwikiLink') " Header levels, 1-6 for s:i in range(1,6) execute 'syntax match VimwikiHeader'.s:i \ . ' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i, s:current_syntax). \ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'. \ 'VimwikiLink,@Spell' execute 'syntax region VimwikiH'.s:i.'Folding start=/'. \ vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_Start', s:current_syntax).'/ end=/'. \ vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_End', s:current_syntax). \ '/me=s-1 transparent fold' endfor let s:options = ' contained transparent contains=NONE' if exists('+conceallevel') let s:options .= b:vimwiki_syntax_conceal endif " A shortener for long URLs: LinkRest (a middle part of the URL) is concealed " VimwikiLinkRest group is left undefined if link shortening is not desired if exists('+conceallevel') && vimwiki#vars#get_global('url_maxsave') > 0 execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\+\ze' \.'\%([/#?]\w\|\S\{'.vimwiki#vars#get_global('url_maxsave').'}\)`'.' cchar=~'.s:options endif " VimwikiLinkChar is for syntax markers (and also URL when a description " is present) and may be concealed " conceal wikilinks execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_prefix').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_suffix').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_prefix1').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_suffix1').'/'.s:options " conceal wikiincls execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclPrefix').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclPrefix1').'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix1').'/'.s:options " non concealed chars execute 'syn match VimwikiHeaderChar contained /\%(^\s*'. \ vimwiki#vars#get_syntaxlocal('rxH').'\+\)\|\%('.vimwiki#vars#get_syntaxlocal('rxH'). \ '\+\s*$\)/' execute 'syntax match VimwikiTodo /'. vimwiki#vars#get_global('rxTodo') .'/' " Tables syntax match VimwikiTableRow /^\s*|.\+|\s*$/ \ transparent contains=VimwikiCellSeparator, \ VimwikiLinkT, \ VimwikiNoExistsLinkT, \ VimwikiTodo, \ VimwikiBoldT, \ VimwikiItalicT, \ VimwikiBoldItalicT, \ VimwikiItalicBoldT, \ VimwikiDelTextT, \ VimwikiSuperScriptT, \ VimwikiSubScriptT, \ VimwikiCodeT, \ VimwikiEqInT, \ @Spell syntax match VimwikiCellSeparator \ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained " Lists execute 'syntax match VimwikiList /'.vimwiki#vars#get_wikilocal('rxListItemWithoutCB').'/' execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListDefine').'/' execute 'syntax match VimwikiListTodo /'.vimwiki#vars#get_wikilocal('rxListItem').'/' if vimwiki#vars#get_global('hl_cb_checked') == 1 execute 'syntax match VimwikiCheckBoxDone /'.vimwiki#vars#get_wikilocal('rxListItemWithoutCB') \ . '\s*\[['.vimwiki#vars#get_wikilocal('listsyms_list')[-1] \ . vimwiki#vars#get_global('listsym_rejected') \ . ']\]\s.*$/ contains=VimwikiNoExistsLink,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell' elseif vimwiki#vars#get_global('hl_cb_checked') == 2 execute 'syntax match VimwikiCheckBoxDone /' \ . vimwiki#vars#get_wikilocal('rxListItemAndChildren') \ .'/ contains=VimwikiNoExistsLink,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell' endif "