" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker: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') call vimwiki#vars#populate_syntax_vars(s:current_syntax) " LINKS: highlighting is complicated due to "nonexistent" links feature {{{ function! s:add_target_syntax_ON(target, type) " {{{ 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) " {{{ 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() "{{{ " 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 = '\%('. \ join(split(vimwiki#vars#get_global('schemes'), '\s*,\s*'), '\|').'\|'. \ join(split(vimwiki#vars#get_global('web_schemes1'), '\s*,\s*'), '\|'). \ '\):' " 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') " }}} " generic headers "{{{ " 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 " }}} " possibly concealed chars " {{{ let s:conceal = exists("+conceallevel") ? ' conceal' : '' execute 'syn match VimwikiEqInChar contained /'.vimwiki#vars#get_syntaxlocal('char_eqin').'/'.s:conceal execute 'syn match VimwikiBoldChar contained /'.vimwiki#vars#get_syntaxlocal('char_bold').'/'.s:conceal execute 'syn match VimwikiItalicChar contained /'.vimwiki#vars#get_syntaxlocal('char_italic').'/'.s:conceal execute 'syn match VimwikiBoldItalicChar contained /'.vimwiki#vars#get_syntaxlocal('char_bolditalic').'/'.s:conceal execute 'syn match VimwikiItalicBoldChar contained /'.vimwiki#vars#get_syntaxlocal('char_italicbold').'/'.s:conceal execute 'syn match VimwikiCodeChar contained /'.vimwiki#vars#get_syntaxlocal('char_code').'/'.s:conceal execute 'syn match VimwikiDelTextChar contained /'.vimwiki#vars#get_syntaxlocal('char_deltext').'/'.s:conceal execute 'syn match VimwikiSuperScript contained /'.vimwiki#vars#get_syntaxlocal('char_superscript').'/'.s:conceal execute 'syn match VimwikiSubScript contained /'.vimwiki#vars#get_syntaxlocal('char_subscript').'/'.s:conceal " }}} " concealed link parts " {{{ " define the conceal attribute for links only if Vim is new enough to handle it " and the user has g:vimwiki_url_maxsave > 0 let s:options = ' contained transparent contains=NONE' " " 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 let s:options .= s:conceal 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 'syn match VimwikiEqInCharT contained /'.vimwiki#vars#get_syntaxlocal('char_eqin').'/' execute 'syn match VimwikiBoldCharT contained /'.vimwiki#vars#get_syntaxlocal('char_bold').'/' execute 'syn match VimwikiItalicCharT contained /'.vimwiki#vars#get_syntaxlocal('char_italic').'/' execute 'syn match VimwikiBoldItalicCharT contained /'.vimwiki#vars#get_syntaxlocal('char_bolditalic').'/' execute 'syn match VimwikiItalicBoldCharT contained /'.vimwiki#vars#get_syntaxlocal('char_italicbold').'/' execute 'syn match VimwikiCodeCharT contained /'.vimwiki#vars#get_syntaxlocal('char_code').'/' execute 'syn match VimwikiDelTextCharT contained /'.vimwiki#vars#get_syntaxlocal('char_deltext').'/' execute 'syn match VimwikiSuperScriptT contained /'.vimwiki#vars#get_syntaxlocal('char_superscript').'/' execute 'syn match VimwikiSubScriptT contained /'.vimwiki#vars#get_syntaxlocal('char_subscript').'/' " Emoticons "syntax match VimwikiEmoticons /\%((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/ execute 'syntax match VimwikiTodo /'. vimwiki#vars#get_global('rxTodo') .'/' " }}} " main syntax groups {{{ " Tables syntax match VimwikiTableRow /^\s*|.\+|\s*$/ \ transparent contains=VimwikiCellSeparator, \ VimwikiLinkT, \ VimwikiNoExistsLinkT, \ VimwikiEmoticons, \ VimwikiTodo, \ VimwikiBoldT, \ VimwikiItalicT, \ VimwikiBoldItalicT, \ VimwikiItalicBoldT, \ VimwikiDelTextT, \ VimwikiSuperScriptT, \ VimwikiSubScriptT, \ VimwikiCodeT, \ VimwikiEqInT, \ @Spell syntax match VimwikiCellSeparator \ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained " Lists execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListItemWithoutCB').'/' execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListDefine').'/' execute 'syntax match VimwikiListTodo /'.vimwiki#vars#get_syntaxlocal('rxListItem').'/' if vimwiki#vars#get_global('hl_cb_checked') == 1 execute 'syntax match VimwikiCheckBoxDone /'.vimwiki#vars#get_syntaxlocal('rxListItemWithoutCB') \ . '\s*\[['.vimwiki#vars#get_syntaxlocal('listsyms_list')[-1] \ . vimwiki#vars#get_global('listsym_rejected') \ . ']\]\s.*$/ contains=VimwikiNoExistsLink,VimwikiLink,@Spell' elseif vimwiki#vars#get_global('hl_cb_checked') == 2 execute 'syntax match VimwikiCheckBoxDone /' \ . vimwiki#vars#get_syntaxlocal('rxListItemAndChildren') \ .'/ contains=VimwikiNoExistsLink,VimwikiLink,@Spell' endif execute 'syntax match VimwikiEqIn /'.vimwiki#vars#get_syntaxlocal('rxEqIn').'/ contains=VimwikiEqInChar' execute 'syntax match VimwikiEqInT /'.vimwiki#vars#get_syntaxlocal('rxEqIn').'/ contained contains=VimwikiEqInCharT' execute 'syntax match VimwikiBold /'.vimwiki#vars#get_syntaxlocal('rxBold').'/ contains=VimwikiBoldChar,@Spell' execute 'syntax match VimwikiBoldT /'.vimwiki#vars#get_syntaxlocal('rxBold').'/ contained contains=VimwikiBoldCharT,@Spell' execute 'syntax match VimwikiItalic /'.vimwiki#vars#get_syntaxlocal('rxItalic').'/ contains=VimwikiItalicChar,@Spell' execute 'syntax match VimwikiItalicT /'.vimwiki#vars#get_syntaxlocal('rxItalic').'/ contained contains=VimwikiItalicCharT,@Spell' execute 'syntax match VimwikiBoldItalic /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').'/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell' execute 'syntax match VimwikiBoldItalicT /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').'/ contained contains=VimwikiBoldItalicChatT,VimwikiItalicBoldCharT,@Spell' execute 'syntax match VimwikiItalicBold /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').'/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell' execute 'syntax match VimwikiItalicBoldT /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').'/ contained contains=VimwikiBoldItalicCharT,VimsikiItalicBoldCharT,@Spell' execute 'syntax match VimwikiDelText /'.vimwiki#vars#get_syntaxlocal('rxDelText').'/ contains=VimwikiDelTextChar,@Spell' execute 'syntax match VimwikiDelTextT /'.vimwiki#vars#get_syntaxlocal('rxDelText').'/ contained contains=VimwikiDelTextChar,@Spell' execute 'syntax match VimwikiSuperScript /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').'/ contains=VimwikiSuperScriptChar,@Spell' execute 'syntax match VimwikiSuperScriptT /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').'/ contained contains=VimwikiSuperScriptCharT,@Spell' execute 'syntax match VimwikiSubScript /'.vimwiki#vars#get_syntaxlocal('rxSubScript').'/ contains=VimwikiSubScriptChar,@Spell' execute 'syntax match VimwikiSubScriptT /'.vimwiki#vars#get_syntaxlocal('rxSubScript').'/ contained contains=VimwikiSubScriptCharT,@Spell' execute 'syntax match VimwikiCode /'.vimwiki#vars#get_syntaxlocal('rxCode').'/ contains=VimwikiCodeChar' execute 'syntax match VimwikiCodeT /'.vimwiki#vars#get_syntaxlocal('rxCode').'/ contained contains=VimwikiCodeCharT' "