table align - catch up to dev

This commit is contained in:
Steven Schmeiser 2018-07-09 13:51:18 -04:00
commit 10f502a698
22 changed files with 3673 additions and 3099 deletions

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2008-2010 Maxim Kim
2013-2017 Daniel Schemala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -135,6 +135,15 @@ Installation using [Pathogen](http://www.vim.org/scripts/script.php?script_id=23
cd bundle cd bundle
git clone https://github.com/vimwiki/vimwiki.git git clone https://github.com/vimwiki/vimwiki.git
Installation using [Vim-Plug](https://github.com/junegunn/vim-plug)
------------------------------------------------------------------------------
Add the following to the plugin-configuration in your vimrc:
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
Then run `:PlugInstall`.
Installation using [Vundle](https://github.com/VundleVim/Vundle.vim) Installation using [Vundle](https://github.com/VundleVim/Vundle.vim)
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@ -146,6 +155,14 @@ Or download the [zip archive](https://github.com/vimwiki/vimwiki/archive/master.
Then launch Vim, run `:Helptags` and then `:help vimwiki` to verify it was installed. Then launch Vim, run `:Helptags` and then `:help vimwiki` to verify it was installed.
Getting help
==============================================================================
Have a question? Visit the IRC channel `#vimwiki` on Freenode ([webchat](https://webchat.freenode.net/?channels=#vimwiki))
or post to the [mailing list](https://groups.google.com/forum/#!forum/vimwiki).
---- ----
\* Screenshots made with the [solarized colorscheme](https://github.com/altercation/vim-colors-solarized) \* Screenshots made with the [solarized colorscheme](https://github.com/altercation/vim-colors-solarized)
and [lightline](https://github.com/itchyny/lightline.vim) and [lightline](https://github.com/itchyny/lightline.vim)

File diff suppressed because it is too large Load Diff

View File

@ -1,76 +1,80 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Handle diary notes " Description: Handle diary notes
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" Load only once {{{
if exists("g:loaded_vimwiki_diary_auto") || &cp if exists("g:loaded_vimwiki_diary_auto") || &cp
finish finish
endif endif
let g:loaded_vimwiki_diary_auto = 1 let g:loaded_vimwiki_diary_auto = 1
"}}}
let s:vimwiki_max_scan_for_caption = 5 let s:vimwiki_max_scan_for_caption = 5
" Helpers {{{
function! s:prefix_zero(num) "{{{ function! s:prefix_zero(num)
if a:num < 10 if a:num < 10
return '0'.a:num return '0'.a:num
endif endif
return a:num return a:num
endfunction "}}} endfunction
function! s:get_date_link(fmt) "{{{
return strftime(a:fmt)
endfunction "}}}
function! s:diary_path(...) "{{{ function! s:diary_path(...)
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1 let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
return VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx) return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
endfunction "}}} endfunction
function! s:diary_index(...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
return s:diary_path(idx).VimwikiGet('diary_index', idx).VimwikiGet('ext', idx)
endfunction "}}}
function! s:diary_date_link(...) "{{{ function! s:diary_index(...)
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1 let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
return s:get_date_link(VimwikiGet('diary_link_fmt', idx)) return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
endfunction "}}} \ vimwiki#vars#get_wikilocal('ext', idx)
endfunction
function! s:get_position_links(link) "{{{
function! vimwiki#diary#diary_date_link(...)
if a:0
return strftime('%Y-%m-%d', a:1)
else
return strftime('%Y-%m-%d')
endif
endfunction
function! s:get_position_links(link)
let idx = -1 let idx = -1
let links = [] let links = []
if a:link =~# '^\d\{4}-\d\d-\d\d' if a:link =~# '^\d\{4}-\d\d-\d\d'
let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")') let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
" include 'today' into links " include 'today' into links
if index(links, s:diary_date_link()) == -1 if index(links, vimwiki#diary#diary_date_link()) == -1
call add(links, s:diary_date_link()) call add(links, vimwiki#diary#diary_date_link())
endif endif
call sort(links) call sort(links)
let idx = index(links, a:link) let idx = index(links, a:link)
endif endif
return [idx, links] return [idx, links]
endfunction "}}} endfunction
fun! s:get_month_name(month) "{{{
return g:vimwiki_diary_months[str2nr(a:month)]
endfun "}}}
" Helpers }}} function! s:get_month_name(month)
return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
endfunction
" Diary index stuff {{{
fun! s:read_captions(files) "{{{ function! s:read_captions(files)
let result = {} let result = {}
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
for fl in a:files for fl in a:files
" remove paths and extensions " remove paths and extensions
let fl_key = fnamemodify(fl, ':t:r') let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '')
if filereadable(fl) if filereadable(fl)
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption) for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
if line =~# g:vimwiki_rxHeader && !has_key(result, fl_key) if line =~# rx_header && !has_key(result, fl_key)
let result[fl_key] = vimwiki#u#trim(matchstr(line, g:vimwiki_rxHeader)) let result[fl_key] = vimwiki#u#trim(matchstr(line, rx_header))
endif endif
endfor endfor
endif endif
@ -81,11 +85,13 @@ fun! s:read_captions(files) "{{{
endfor endfor
return result return result
endfun "}}} endfunction
fun! s:get_diary_files() "{{{
function! s:get_diary_files()
let rx = '^\d\{4}-\d\d-\d\d' let rx = '^\d\{4}-\d\d-\d\d'
let s_files = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').'*'.VimwikiGet('ext')) let s_files = glob(vimwiki#vars#get_wikilocal('path').
\ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
let files = split(s_files, '\n') let files = split(s_files, '\n')
call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"') call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
@ -93,9 +99,10 @@ fun! s:get_diary_files() "{{{
call filter(files, 'v:val !~# ''.*\~$''') call filter(files, 'v:val !~# ''.*\~$''')
return files return files
endfun "}}} endfunction
fun! s:group_links(links) "{{{
function! s:group_links(links)
let result = {} let result = {}
let p_year = 0 let p_year = 0
let p_month = 0 let p_month = 0
@ -114,83 +121,104 @@ fun! s:group_links(links) "{{{
let p_month = month let p_month = month
endfor endfor
return result return result
endfun "}}} endfunction
function! s:sort(lst) "{{{
if VimwikiGet("diary_sort") ==? 'desc' function! s:sort(lst)
if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
return reverse(sort(a:lst)) return reverse(sort(a:lst))
else else
return sort(a:lst) return sort(a:lst)
endif endif
endfunction "}}} endfunction
function! s:format_diary() "{{{
function! s:format_diary()
let result = [] let result = []
let links_with_captions = s:read_captions(s:get_diary_files()) let links_with_captions = s:read_captions(s:get_diary_files())
let g_files = s:group_links(links_with_captions) let g_files = s:group_links(links_with_captions)
for year in s:sort(keys(g_files)) for year in s:sort(keys(g_files))
call add(result, '') call add(result, '')
call add(result, substitute(g:vimwiki_rxH2_Template, '__Header__', year , '')) call add(result,
\ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
for month in s:sort(keys(g_files[year])) for month in s:sort(keys(g_files[year]))
call add(result, '') call add(result, '')
call add(result, substitute(g:vimwiki_rxH3_Template, '__Header__', s:get_month_name(month), '')) call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
\ '__Header__', s:get_month_name(month), ''))
for [fl, cap] in s:sort(items(g_files[year][month])) for [fl, cap] in s:sort(items(g_files[year][month]))
if empty(cap) let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
let entry = substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', fl, '')
let entry = substitute(entry, '__LinkDescription__', cap, '') if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
call add(result, repeat(' ', &sw).'* '.entry) let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
else
let entry = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__', fl, '') if empty(cap) " When using markdown syntax, we should ensure we always have a link description.
let entry = substitute(entry, '__LinkDescription__', cap, '') let cap = fl
call add(result, repeat(' ', &sw).'* '.entry) endif
elseif empty(cap)
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
endif endif
let entry = substitute(link_tpl, '__LinkUrl__', fl, '')
let entry = substitute(entry, '__LinkDescription__', cap, '')
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
endfor endfor
endfor endfor
endfor endfor
return result return result
endfunction "}}} endfunction
" Diary index stuff }}}
function! vimwiki#diary#make_note(wnum, ...) "{{{ " The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
if a:wnum > len(g:vimwiki_list) " contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!' " is used.
function! vimwiki#diary#make_note(wnum, ...)
if a:wnum == 0
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
if wiki_nr < 0 " this happens when e.g. VimwikiMakeDiaryNote was called outside a wiki buffer
let wiki_nr = 0
endif
else
let wiki_nr = a:wnum - 1
endif
if wiki_nr >= vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.wiki_nr.' is not registered in g:vimwiki_list!'
return return
endif endif
" TODO: refactor it. base#goto_index uses the same " TODO: refactor it. base#goto_index uses the same
if a:wnum > 0
let idx = a:wnum - 1
else
let idx = 0
endif
call vimwiki#path#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
if a:0 && a:1 == 1 let cmd = 'edit'
let cmd = 'tabedit' if a:0
else if a:1 == 1
let cmd = 'edit' let cmd = 'tabedit'
elseif a:1 == 2
let cmd = 'split'
elseif a:1 == 3
let cmd = 'vsplit'
endif
endif endif
if a:0>1 if a:0>1
let link = 'diary:'.a:2 let link = 'diary:'.a:2
else else
let link = 'diary:'.s:diary_date_link(idx) let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
call vimwiki#base#open_link(cmd, link, s:diary_index(idx)) call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr))
call vimwiki#base#setup_buffer_state(idx) endfunction
endfunction "}}}
function! vimwiki#diary#goto_diary_index(wnum) "{{{
if a:wnum > len(g:vimwiki_list) function! vimwiki#diary#goto_diary_index(wnum)
if a:wnum > vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!' echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
return return
endif endif
@ -203,10 +231,10 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
endif endif
call vimwiki#base#edit_file('e', s:diary_index(idx), '') call vimwiki#base#edit_file('e', s:diary_index(idx), '')
call vimwiki#base#setup_buffer_state(idx) endfunction
endfunction "}}}
function! vimwiki#diary#goto_next_day() "{{{
function! vimwiki#diary#goto_next_day()
let link = '' let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r')) let [idx, links] = s:get_position_links(expand('%:t:r'))
@ -218,15 +246,16 @@ function! vimwiki#diary#goto_next_day() "{{{
let link = 'diary:'.links[idx+1] let link = 'diary:'.links[idx+1]
else else
" goto today " goto today
let link = 'diary:'.s:diary_date_link() let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
if len(link) if len(link)
call vimwiki#base#open_link(':e ', link) call vimwiki#base#open_link(':e ', link)
endif endif
endfunction "}}} endfunction
function! vimwiki#diary#goto_prev_day() "{{{
function! vimwiki#diary#goto_prev_day()
let link = '' let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r')) let [idx, links] = s:get_position_links(expand('%:t:r'))
@ -238,29 +267,30 @@ function! vimwiki#diary#goto_prev_day() "{{{
let link = 'diary:'.links[idx-1] let link = 'diary:'.links[idx-1]
else else
" goto today " goto today
let link = 'diary:'.s:diary_date_link() let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
if len(link) if len(link)
call vimwiki#base#open_link(':e ', link) call vimwiki#base#open_link(':e ', link)
endif endif
endfunction "}}} endfunction
function! vimwiki#diary#generate_diary_section() "{{{
function! vimwiki#diary#generate_diary_section()
let current_file = vimwiki#path#path_norm(expand("%:p")) let current_file = vimwiki#path#path_norm(expand("%:p"))
let diary_file = vimwiki#path#path_norm(s:diary_index()) let diary_file = vimwiki#path#path_norm(s:diary_index())
if vimwiki#path#is_equal(current_file, diary_file) if vimwiki#path#is_equal(current_file, diary_file)
let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.g:vimwiki_rxHeader.'\)' let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(), call vimwiki#base#update_listing_in_buffer(s:format_diary(),
\ VimwikiGet('diary_header'), content_rx, line('$')+1, 1) \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
else else
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!' echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
endif endif
endfunction "}}} endfunction
" Calendar.vim {{{
" Callback function. " Callback function for Calendar.vim
function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{ function! vimwiki#diary#calendar_action(day, month, year, week, dir)
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
@ -278,18 +308,15 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
endif endif
endif endif
" XXX: Well, +1 is for inconsistent index basing... call vimwiki#diary#make_note(0, 0, link)
call vimwiki#diary#make_note(g:vimwiki_current_idx+1, 0, link) endfunction
endfunction "}}}
" Sign function.
function vimwiki#diary#calendar_sign(day, month, year) "{{{ function vimwiki#diary#calendar_sign(day, month, year)
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path'). let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').
\ a:year.'-'.month.'-'.day.VimwikiGet('ext') \ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
return filereadable(expand(sfile)) return filereadable(expand(sfile))
endfunction "}}} endfunction
" Calendar.vim }}}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +1,44 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Link functions for markdown syntax " Description: Link functions for markdown syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" MISC helper functions {{{ function! s:safesubstitute(text, search, replace, mode)
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode)
endfunction
" vimwiki#markdown_base#reset_mkd_refs
function! vimwiki#markdown_base#reset_mkd_refs() "{{{
call VimwikiClear('markdown_refs')
endfunction "}}}
" vimwiki#markdown_base#scan_reflinks function! vimwiki#markdown_base#scan_reflinks()
function! vimwiki#markdown_base#scan_reflinks() " {{{
let mkd_refs = {} let mkd_refs = {}
" construct list of references using vimgrep " construct list of references using vimgrep
try try
" Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121 " Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121
noautocmd execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %' noautocmd execute 'vimgrep #'.vimwiki#vars#get_syntaxlocal('rxMkdRef').'#j %'
catch /^Vim\%((\a\+)\)\=:E480/ " No Match catch /^Vim\%((\a\+)\)\=:E480/ " No Match
"Ignore it, and move on to the next file "Ignore it, and move on to the next file
endtry endtry
"
for d in getqflist() for d in getqflist()
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ') let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
let descr = matchstr(matchline, g:vimwiki_rxMkdRefMatchDescr) let descr = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchDescr'))
let url = matchstr(matchline, g:vimwiki_rxMkdRefMatchUrl) let url = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchUrl'))
if descr != '' && url != '' if descr != '' && url != ''
let mkd_refs[descr] = url let mkd_refs[descr] = url
endif endif
endfor endfor
call VimwikiSet('markdown_refs', mkd_refs) call vimwiki#vars#set_bufferlocal('markdown_refs', mkd_refs)
return mkd_refs return mkd_refs
endfunction "}}} endfunction
" vimwiki#markdown_base#get_reflinks
function! vimwiki#markdown_base#get_reflinks() " {{{
let done = 1
try
let mkd_refs = VimwikiGet('markdown_refs')
catch
" work-around hack
let done = 0
" ... the following command does not work inside catch block !?
" > let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endtry
if !done
let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endif
return mkd_refs
endfunction "}}}
" vimwiki#markdown_base#open_reflink
" try markdown reference links " try markdown reference links
function! vimwiki#markdown_base#open_reflink(link) " {{{ function! vimwiki#markdown_base#open_reflink(link)
" echom "vimwiki#markdown_base#open_reflink" " echom "vimwiki#markdown_base#open_reflink"
let link = a:link let link = a:link
let mkd_refs = vimwiki#markdown_base#get_reflinks() let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs')
if has_key(mkd_refs, link) if has_key(mkd_refs, link)
let url = mkd_refs[link] let url = mkd_refs[link]
call vimwiki#base#system_open_link(url) call vimwiki#base#system_open_link(url)
@ -65,70 +46,68 @@ function! vimwiki#markdown_base#open_reflink(link) " {{{
else else
return 0 return 0
endif endif
endfunction " }}} endfunction
" }}}
" WIKI link following functions {{{
" LINK functions {{{ function! s:normalize_link_syntax_n()
" s:normalize_link_syntax_n
function! s:normalize_link_syntax_n() " {{{
let lnum = line('.') let lnum = line('.')
" try WikiIncl " try WikiIncl
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl'))
if !empty(lnk) if !empty(lnk)
" NO-OP !! " NO-OP !!
return return
endif endif
" try WikiLink0: replace with WikiLink1 " try WikiLink0: replace with WikiLink1
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink0) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr, \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
\ g:vimwiki_WikiLink1Template2) \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink0, sub) \ vimwiki#vars#get_syntaxlocal('WikiLink1Template2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'), sub)
return return
endif endif
" try WikiLink1: replace with WikiLink0 " try WikiLink1: replace with WikiLink0
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink1) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr, \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
\ g:vimwiki_WikiLinkTemplate2) \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink1, sub) \ vimwiki#vars#get_global('WikiLinkTemplate2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), sub)
return return
endif endif
" try Weblink " try Weblink
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWeblinkMatchUrl, g:vimwiki_rxWeblinkMatchDescr, \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'),
\ g:vimwiki_Weblink1Template) \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'),
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWeblink, sub) \ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
return return
endif endif
" try Word (any characters except separators) " try Word (any characters except separators)
" rxWord is less permissive than rxWikiLinkUrl which is used in " rxWord is less permissive than rxWikiLinkUrl which is used in
" normalize_link_syntax_v " normalize_link_syntax_v
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWord) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWord'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWord, '', \ vimwiki#vars#get_global('rxWord'), '',
\ g:vimwiki_Weblink1Template) \ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub) call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
return return
endif endif
endfunction " }}} endfunction
" s:normalize_link_syntax_v
function! s:normalize_link_syntax_v() " {{{ function! s:normalize_link_syntax_v()
let lnum = line('.') let lnum = line('.')
let sel_save = &selection let sel_save = &selection
let &selection = "old" let &selection = "old"
@ -139,10 +118,11 @@ function! s:normalize_link_syntax_v() " {{{
try try
norm! gvy norm! gvy
let visual_selection = @" let visual_selection = @"
let link = substitute(g:vimwiki_Weblink1Template, '__LinkUrl__', '\='."'".visual_selection."'", '') let link = s:safesubstitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'),
let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '') \ '__LinkUrl__', visual_selection, '')
let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '')
call setreg('"', link, 'v') call setreg('"', substitute(link, '\n', '', ''), visualmode())
" paste result " paste result
norm! `>""pgvd norm! `>""pgvd
@ -152,25 +132,19 @@ function! s:normalize_link_syntax_v() " {{{
let &selection = sel_save let &selection = sel_save
endtry endtry
endfunction " }}} endfunction
" vimwiki#base#normalize_link
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{ function! vimwiki#markdown_base#normalize_link(is_visual_mode)
if 0 if 0
" Syntax-specific links " Syntax-specific links
else else
if !a:is_visual_mode if !a:is_visual_mode
call s:normalize_link_syntax_n() call s:normalize_link_syntax_n()
elseif visualmode() ==# 'v' && line("'<") == line("'>") elseif line("'<") == line("'>")
" action undefined for 'line-wise' or 'multi-line' visual mode selections " action undefined for multi-line visual mode selections
call s:normalize_link_syntax_v() call s:normalize_link_syntax_v()
endif endif
endif endif
endfunction "}}} endfunction
" }}}
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
" -------------------------------------------------------------------------

View File

@ -1,15 +1,15 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Path manipulation functions " Description: Path manipulation functions
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
function! vimwiki#path#chomp_slash(str) "{{{ function! vimwiki#path#chomp_slash(str)
return substitute(a:str, '[/\\]\+$', '', '') return substitute(a:str, '[/\\]\+$', '', '')
endfunction "}}} endfunction
" Define path-compare function, either case-sensitive or not, depending on OS. " Define path-compare function, either case-sensitive or not, depending on OS.
"{{{ " function! vimwiki#path#is_equal(p1, p2)
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
function! vimwiki#path#is_equal(p1, p2) function! vimwiki#path#is_equal(p1, p2)
return a:p1 ==? a:p2 return a:p1 ==? a:p2
@ -18,10 +18,11 @@ else
function! vimwiki#path#is_equal(p1, p2) function! vimwiki#path#is_equal(p1, p2)
return a:p1 ==# a:p2 return a:p1 ==# a:p2
endfunction endfunction
endif "}}} endif
" collapse sections like /a/b/../c to /a/c " collapse sections like /a/b/../c to /a/c
function! vimwiki#path#normalize(path) "{{{ function! vimwiki#path#normalize(path)
let path = a:path let path = a:path
while 1 while 1
let result = substitute(path, '/[^/]\+/\.\.', '', '') let result = substitute(path, '/[^/]\+/\.\.', '', '')
@ -31,9 +32,10 @@ function! vimwiki#path#normalize(path) "{{{
let path = result let path = result
endwhile endwhile
return result return result
endfunction "}}} endfunction
function! vimwiki#path#path_norm(path) "{{{
function! vimwiki#path#path_norm(path)
" /-slashes " /-slashes
if a:path !~# '^scp:' if a:path !~# '^scp:'
let path = substitute(a:path, '\', '/', 'g') let path = substitute(a:path, '\', '/', 'g')
@ -44,21 +46,24 @@ function! vimwiki#path#path_norm(path) "{{{
else else
return a:path return a:path
endif endif
endfunction "}}} endfunction
function! vimwiki#path#is_link_to_dir(link) "{{{
function! vimwiki#path#is_link_to_dir(link)
" Check if link is to a directory. " Check if link is to a directory.
" It should be ended with \ or /. " It should be ended with \ or /.
return a:link =~# '\m[/\\]$' return a:link =~# '\m[/\\]$'
endfunction "}}} endfunction
function! vimwiki#path#abs_path_of_link(link) "{{{
function! vimwiki#path#abs_path_of_link(link)
return vimwiki#path#normalize(expand("%:p:h").'/'.a:link) return vimwiki#path#normalize(expand("%:p:h").'/'.a:link)
endfunction "}}} endfunction
" return longest common path prefix of 2 given paths. " return longest common path prefix of 2 given paths.
" '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki' " '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki'
function! vimwiki#path#path_common_pfx(path1, path2) "{{{ function! vimwiki#path#path_common_pfx(path1, path2)
let p1 = split(a:path1, '[/\\]', 1) let p1 = split(a:path1, '[/\\]', 1)
let p2 = split(a:path2, '[/\\]', 1) let p2 = split(a:path2, '[/\\]', 1)
@ -72,16 +77,17 @@ function! vimwiki#path#path_common_pfx(path1, path2) "{{{
else else
return join(p1[: idx-1], '/') return join(p1[: idx-1], '/')
endif endif
endfunction "}}} endfunction
function! vimwiki#path#wikify_path(path) "{{{
function! vimwiki#path#wikify_path(path)
let result = resolve(fnamemodify(a:path, ':p')) let result = resolve(fnamemodify(a:path, ':p'))
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
let result = substitute(result, '\\', '/', 'g') let result = substitute(result, '\\', '/', 'g')
endif endif
let result = vimwiki#path#chomp_slash(result) let result = vimwiki#path#chomp_slash(result)
return result return result
endfunction "}}} endfunction
function! vimwiki#path#current_wiki_file() function! vimwiki#path#current_wiki_file()
@ -90,7 +96,7 @@ endfunction
" Returns: the relative path from a:dir to a:file " Returns: the relative path from a:dir to a:file
function! vimwiki#path#relpath(dir, file) "{{{ function! vimwiki#path#relpath(dir, file)
let result = [] let result = []
let dir = split(a:dir, '/') let dir = split(a:dir, '/')
let file = split(a:file, '/') let file = split(a:file, '/')
@ -112,12 +118,13 @@ function! vimwiki#path#relpath(dir, file) "{{{
let result_path .= '/' let result_path .= '/'
endif endif
return result_path return result_path
endfunction "}}} endfunction
" If the optional argument provided and nonzero, " If the optional argument provided and nonzero,
" it will ask before creating a directory " it will ask before creating a directory
" Returns: 1 iff directory exists or successfully created " Returns: 1 iff directory exists or successfully created
function! vimwiki#path#mkdir(path, ...) "{{{ function! vimwiki#path#mkdir(path, ...)
let path = expand(a:path) let path = expand(a:path)
if path =~# '^scp:' if path =~# '^scp:'
@ -133,27 +140,27 @@ function! vimwiki#path#mkdir(path, ...) "{{{
endif endif
let path = vimwiki#path#chomp_slash(path) let path = vimwiki#path#chomp_slash(path)
if vimwiki#u#is_windows() && !empty(g:vimwiki_w32_dir_enc) if vimwiki#u#is_windows() && !empty(vimwiki#vars#get_global('w32_dir_enc'))
let path = iconv(path, &enc, g:vimwiki_w32_dir_enc) let path = iconv(path, &enc, vimwiki#vars#get_global('w32_dir_enc'))
endif endif
if a:0 && a:1 && input("Vimwiki: Make new directory: " if a:0 && a:1 && input("Vimwiki: Make new directory: ".path."\n [y]es/[N]o? ") !~? '^y'
\ .path."\n [y]es/[N]o? ") !~? '^y'
return 0 return 0
endif endif
call mkdir(path, "p") call mkdir(path, "p")
return 1 return 1
endif endif
endfunction " }}} endfunction
function! vimwiki#path#is_absolute(path) "{{{
function! vimwiki#path#is_absolute(path)
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
return a:path =~? '\m^\a:' return a:path =~? '\m^\a:'
else else
return a:path =~# '\m^/\|\~/' return a:path =~# '\m^/\|\~/'
endif endif
endfunction "}}} endfunction
" Combine a directory and a file into one path, doesn't generate duplicate " Combine a directory and a file into one path, doesn't generate duplicate
@ -173,3 +180,4 @@ else
return directory . '/' . file return directory . '/' . file
endfunction endfunction
endif endif

View File

@ -27,6 +27,13 @@ del {text-decoration: line-through; color: #777777;}
.tag {background-color: #eeeeee; font-family: monospace; padding: 2px;} .tag {background-color: #eeeeee; font-family: monospace; padding: 2px;}
/* classes for items of todo lists */ /* classes for items of todo lists */
.rejected {
/* list-style: none; */
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAACXBIWXMAAADFAAAAxQEdzbqoAAAAB3RJTUUH4QgEFhAtuWgv9wAAAPZQTFRFmpqam5iYnJaWnJeXnpSUn5OTopCQpoqKpouLp4iIqIiIrYCAt3V1vW1tv2xsmZmZmpeXnpKS/x4e/x8f/yAg/yIi/yQk/yUl/yYm/ygo/ykp/yws/zAw/zIy/zMz/zQ0/zU1/zY2/zw8/0BA/0ZG/0pK/1FR/1JS/1NT/1RU/1VV/1ZW/1dX/1pa/15e/19f/2Zm/2lp/21t/25u/3R0/3p6/4CA/4GB/4SE/4iI/46O/4+P/52d/6am/6ur/66u/7Oz/7S0/7e3/87O/9fX/9zc/93d/+Dg/+vr/+3t/+/v//Dw//Ly//X1//f3//n5//z8////gzaKowAAAA90Uk5T/Pz8/Pz8/Pz8/Pz8/f39ppQKWQAAAAFiS0dEEnu8bAAAAACuSURBVAhbPY9ZF4FQFEZPSKbIMmWep4gMGTKLkIv6/3/GPbfF97b3w17rA0kQOPgvAeHW6uJ6+5h7HqLdwowgOzejXRXBdx6UdSru216xuOMBHHNU0clTzeSUA6EhF8V8kqroluMiU6HKcuf4phGPr1o2q9kYZWwNq1qfRRmTaXpqsyjj17KkWCxKBUBgXWueHIyiAIg18gsse4KHkLF5IKIY10WQgv7fOy4ST34BRiopZ8WLNrgAAAAASUVORK5CYII=);
background-repeat: no-repeat;
background-position: 0 .2em;
padding-left: 1.5em;
}
.done0 { .done0 {
/* list-style: none; */ /* list-style: none; */
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==); background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==);

View File

@ -1,9 +1,11 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
let s:TAGS_METADATA_FILE_NAME = '.tags' let s:TAGS_METADATA_FILE_NAME = '.tags'
" Tags metadata in-memory format: " Tags metadata in-memory format:
" metadata := { 'pagename': [entries, ...] } " metadata := { 'pagename': [entries, ...] }
" entry := { 'tagname':..., 'lineno':..., 'link':... } " entry := { 'tagname':..., 'lineno':..., 'link':... }
@ -19,16 +21,17 @@ let s:TAGS_METADATA_FILE_NAME = '.tags'
" an optional field, "vimwiki:". In this field, we encode tab-separated values " an optional field, "vimwiki:". In this field, we encode tab-separated values
" of missing parameters -- "pagename" and "link". " of missing parameters -- "pagename" and "link".
" vimwiki#tags#update_tags
" Update tags metadata. " Update tags metadata.
" a:full_rebuild == 1: re-scan entire wiki " a:full_rebuild == 1: re-scan entire wiki
" a:full_rebuild == 0: only re-scan current page " a:full_rebuild == 0: only re-scan current page
" a:all_files == '': only if the file is newer than .tags " a:all_files == '': only if the file is newer than .tags
function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{ function! vimwiki#tags#update_tags(full_rebuild, all_files)
let all_files = a:all_files != '' let all_files = a:all_files != ''
if !a:full_rebuild if !a:full_rebuild
" Updating for one page (current) " Updating for one page (current)
let page_name = VimwikiGet('subdir') . expand('%:t:r') let page_name = vimwiki#vars#get_bufferlocal('subdir') . expand('%:t:r')
" Collect tags in current file " Collect tags in current file
let tags = s:scan_tags(getline(1, '$'), page_name) let tags = s:scan_tags(getline(1, '$'), page_name)
" Load metadata file " Load metadata file
@ -40,10 +43,9 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
" Save " Save
call s:write_tags_metadata(metadata) call s:write_tags_metadata(metadata)
else " full rebuild else " full rebuild
let files = vimwiki#base#find_files(g:vimwiki_current_idx, 0) let files = vimwiki#base#find_files(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
let wiki_base_dir = VimwikiGet('path', g:vimwiki_current_idx) let wiki_base_dir = vimwiki#vars#get_wikilocal('path')
let tags_file_last_modification = let tags_file_last_modification = getftime(vimwiki#tags#metadata_file_path())
\ getftime(vimwiki#tags#metadata_file_path())
let metadata = s:load_tags_metadata() let metadata = s:load_tags_metadata()
for file in files for file in files
if all_files || getftime(file) >= tags_file_last_modification if all_files || getftime(file) >= tags_file_last_modification
@ -56,20 +58,19 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
endfor endfor
call s:write_tags_metadata(metadata) call s:write_tags_metadata(metadata)
endif endif
endfunction " }}} endfunction
" s:scan_tags
" Scans the list of text lines (argument) and produces tags metadata as a " Scans the list of text lines (argument) and produces tags metadata as a list of tag entries.
" list of tag entries. function! s:scan_tags(lines, page_name)
function! s:scan_tags(lines, page_name) "{{{
let entries = [] let entries = []
" Code wireframe to scan for headers -- borrowed from " Code wireframe to scan for headers -- borrowed from
" vimwiki#base#get_anchors(), with minor modifications. " vimwiki#base#get_anchors(), with minor modifications.
let rxheader = g:vimwiki_{VimwikiGet('syntax')}_header_search let rxheader = vimwiki#vars#get_syntaxlocal('header_search')
let rxtag = g:vimwiki_{VimwikiGet('syntax')}_tag_search let rxtag = vimwiki#vars#get_syntaxlocal('tag_search')
let anchor_level = ['', '', '', '', '', '', ''] let anchor_level = ['', '', '', '', '', '', '']
let current_complete_anchor = '' let current_complete_anchor = ''
@ -136,17 +137,18 @@ function! s:scan_tags(lines, page_name) "{{{
endfor " loop over lines endfor " loop over lines
return entries return entries
endfunction " }}} endfunction
" vimwiki#tags#metadata_file_path
" Returns tags metadata file path " Returns tags metadata file path
function! vimwiki#tags#metadata_file_path() abort "{{{ function! vimwiki#tags#metadata_file_path() abort
return fnamemodify(vimwiki#path#join_path(VimwikiGet('path'), s:TAGS_METADATA_FILE_NAME), ':p') return fnamemodify(vimwiki#path#join_path(vimwiki#vars#get_wikilocal('path'),
endfunction " }}} \ s:TAGS_METADATA_FILE_NAME), ':p')
endfunction
" s:load_tags_metadata
" Loads tags metadata from file, returns a dictionary " Loads tags metadata from file, returns a dictionary
function! s:load_tags_metadata() abort "{{{ function! s:load_tags_metadata() abort
let metadata_path = vimwiki#tags#metadata_file_path() let metadata_path = vimwiki#tags#metadata_file_path()
if !filereadable(metadata_path) if !filereadable(metadata_path)
return {} return {}
@ -193,29 +195,29 @@ function! s:load_tags_metadata() abort "{{{
endif endif
endfor endfor
return metadata return metadata
endfunction " }}} endfunction
" s:remove_page_from_tags
" Removes all entries for given page from metadata in-place. Returns updated " Removes all entries for given page from metadata in-place. Returns updated
" metadata (just in case). " metadata (just in case).
function! s:remove_page_from_tags(metadata, page_name) "{{{ function! s:remove_page_from_tags(metadata, page_name)
if has_key(a:metadata, a:page_name) if has_key(a:metadata, a:page_name)
call remove(a:metadata, a:page_name) call remove(a:metadata, a:page_name)
return a:metadata return a:metadata
else else
return a:metadata return a:metadata
endif endif
endfunction " }}} endfunction
" s:merge_tags
" Merges metadata of one file into a:metadata " Merges metadata of one file into a:metadata
function! s:merge_tags(metadata, pagename, file_metadata) "{{{ function! s:merge_tags(metadata, pagename, file_metadata)
let metadata = a:metadata let metadata = a:metadata
let metadata[a:pagename] = a:file_metadata let metadata[a:pagename] = a:file_metadata
return metadata return metadata
endfunction " }}} endfunction
" s:tags_entry_cmp
" Compares two actual lines from tags file. Return value is in strcmp style. " Compares two actual lines from tags file. Return value is in strcmp style.
" See help on sort() -- that's what this function is going to be used for. " See help on sort() -- that's what this function is going to be used for.
" See also s:write_tags_metadata below -- that's where we compose these tags " See also s:write_tags_metadata below -- that's where we compose these tags
@ -225,7 +227,7 @@ endfunction " }}}
" numbers as strings, not integers, and so, for example, tag at line 14 " numbers as strings, not integers, and so, for example, tag at line 14
" preceeds the same tag on the same page at line 9. (Because string "14" is " preceeds the same tag on the same page at line 9. (Because string "14" is
" alphabetically 'less than' string "9".) " alphabetically 'less than' string "9".)
function! s:tags_entry_cmp(i1, i2) "{{{ function! s:tags_entry_cmp(i1, i2)
let items = [] let items = []
for orig_item in [a:i1, a:i2] for orig_item in [a:i1, a:i2]
let fields = split(orig_item, "\t") let fields = split(orig_item, "\t")
@ -245,11 +247,11 @@ function! s:tags_entry_cmp(i1, i2) "{{{
else else
return 0 return 0
endif endif
endfunction " }}} endfunction
" s:write_tags_metadata
" Saves metadata object into a file. Throws exceptions in case of problems. " Saves metadata object into a file. Throws exceptions in case of problems.
function! s:write_tags_metadata(metadata) "{{{ function! s:write_tags_metadata(metadata)
let metadata_path = vimwiki#tags#metadata_file_path() let metadata_path = vimwiki#tags#metadata_file_path()
let tags = [] let tags = []
for pagename in keys(a:metadata) for pagename in keys(a:metadata)
@ -261,7 +263,7 @@ function! s:write_tags_metadata(metadata) "{{{
let entry_data = substitute(entry_data, "\n", '\\n', 'g') let entry_data = substitute(entry_data, "\n", '\\n', 'g')
call add(tags, call add(tags,
\ entry.tagname . "\t" \ entry.tagname . "\t"
\ . pagename . VimwikiGet('ext') . "\t" \ . pagename . vimwiki#vars#get_wikilocal('ext') . "\t"
\ . entry.lineno \ . entry.lineno
\ . ';"' \ . ';"'
\ . "\t" . "vimwiki:" . entry_data \ . "\t" . "vimwiki:" . entry_data
@ -271,11 +273,11 @@ function! s:write_tags_metadata(metadata) "{{{
call sort(tags, "s:tags_entry_cmp") call sort(tags, "s:tags_entry_cmp")
call insert(tags, "!_TAG_FILE_SORTED\t1\t") call insert(tags, "!_TAG_FILE_SORTED\t1\t")
call writefile(tags, metadata_path) call writefile(tags, metadata_path)
endfunction " }}} endfunction
" vimwiki#tags#get_tags
" Returns list of unique tags found in the .tags file " Returns list of unique tags found in the .tags file
function! vimwiki#tags#get_tags() "{{{ function! vimwiki#tags#get_tags()
let metadata = s:load_tags_metadata() let metadata = s:load_tags_metadata()
let tags = {} let tags = {}
for entries in values(metadata) for entries in values(metadata)
@ -284,13 +286,13 @@ function! vimwiki#tags#get_tags() "{{{
endfor endfor
endfor endfor
return keys(tags) return keys(tags)
endfunction " }}} endfunction
" vimwiki#tags#generate_tags
" Similar to vimwiki#base#generate_links. In the current buffer, appends " Similar to vimwiki#base#generate_links. In the current buffer, appends
" tags and references to all their instances. If no arguments (tags) are " tags and references to all their instances. If no arguments (tags) are
" specified, outputs all tags. " specified, outputs all tags.
function! vimwiki#tags#generate_tags(...) abort "{{{ function! vimwiki#tags#generate_tags(...) abort
let need_all_tags = (a:0 == 0) let need_all_tags = (a:0 == 0)
let specific_tags = a:000 let specific_tags = a:000
@ -309,34 +311,32 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
endfor endfor
let lines = [] let lines = []
let bullet = repeat(' ', vimwiki#lst#get_list_margin()). let bullet = repeat(' ', vimwiki#lst#get_list_margin()).vimwiki#lst#default_symbol().' '
\ vimwiki#lst#default_symbol().' '
for tagname in sort(keys(tags_entries)) for tagname in sort(keys(tags_entries))
if need_all_tags || index(specific_tags, tagname) != -1 if need_all_tags || index(specific_tags, tagname) != -1
call extend(lines, [ call extend(lines, [
\ '', \ '',
\ substitute(g:vimwiki_rxH2_Template, '__Header__', tagname, ''), \ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', tagname, ''),
\ '' ]) \ '' ])
for taglink in sort(tags_entries[tagname]) for taglink in sort(tags_entries[tagname])
call add(lines, bullet . call add(lines, bullet . substitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
\ substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', taglink, '')) \ '__LinkUrl__', taglink, ''))
endfor endfor
endif endif
endfor endfor
let links_rx = '\m\%(^\s*$\)\|\%('.g:vimwiki_rxH2.'\)\|\%(^\s*' let links_rx = '\m\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxH2').'\)\|\%(^\s*'
\ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' ' \ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
\ .g:vimwiki_rxWikiLink.'$\)' \ .vimwiki#vars#get_syntaxlocal('rxWikiLink').'$\)'
call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, line('$')+1, 1)
\ line('$')+1, 1) endfunction
endfunction " }}}
" vimwiki#tags#complete_tags
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort " {{{ function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort
" We can safely ignore args if we use -custom=complete option, Vim engine " We can safely ignore args if we use -custom=complete option, Vim engine
" will do the job of filtering. " will do the job of filtering.
let taglist = vimwiki#tags#get_tags() let taglist = vimwiki#tags#get_tags()
return join(taglist, "\n") return join(taglist, "\n")
endfunction " }}} endfunction

View File

@ -1,35 +1,36 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Tables " Description: Tables
" | Easily | manageable | text | tables | ! | " | Easily | manageable | text | tables | ! |
" |--------|------------|-------|--------|---------| " |--------|------------|-------|--------|---------|
" | Have | fun! | Drink | tea | Period. | " | Have | fun! | Drink | tea | Period. |
" "
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" Load only once {{{
if exists("g:loaded_vimwiki_tbl_auto") || &cp if exists("g:loaded_vimwiki_tbl_auto") || &cp
finish finish
endif endif
let g:loaded_vimwiki_tbl_auto = 1 let g:loaded_vimwiki_tbl_auto = 1
"}}}
let s:textwidth = &tw let s:textwidth = &tw
" Misc functions {{{ function! s:rxSep()
function! s:rxSep() "{{{ return vimwiki#vars#get_syntaxlocal('rxTableSep')
return g:vimwiki_rxTableSep endfunction
endfunction "}}}
function! s:wide_len(str) "{{{
function! s:wide_len(str)
" vim73 has new function that gives correct string width. " vim73 has new function that gives correct string width.
if exists("*strdisplaywidth") if exists("*strdisplaywidth")
return strdisplaywidth(a:str) return strdisplaywidth(a:str)
endif endif
" get str display width in vim ver < 7.2 " get str display width in vim ver < 7.2
if !g:vimwiki_CJK_length if !vimwiki#vars#get_global('CJK_length')
let ret = strlen(substitute(a:str, '.', 'x', 'g')) let ret = strlen(substitute(a:str, '.', 'x', 'g'))
else else
let savemodified = &modified let savemodified = &modified
@ -42,42 +43,54 @@ function! s:wide_len(str) "{{{
let &modified = savemodified let &modified = savemodified
endif endif
return ret return ret
endfunction "}}} endfunction
function! s:cell_splitter() "{{{
function! s:cell_splitter()
return '\s*'.s:rxSep().'\s*' return '\s*'.s:rxSep().'\s*'
endfunction "}}} endfunction
function! s:sep_splitter() "{{{
function! s:sep_splitter()
return '-'.s:rxSep().'-' return '-'.s:rxSep().'-'
endfunction "}}} endfunction
function! s:is_table(line) "{{{
return s:is_separator(a:line) || (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
endfunction "}}}
function! s:is_separator(line) "{{{ function! s:is_table(line)
return s:is_separator(a:line) ||
\ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
endfunction
function! s:is_separator(line)
return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$' return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$'
endfunction "}}} endfunction
function! s:is_separator_tail(line) "{{{
function! s:is_separator_tail(line)
return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$' return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$'
endfunction "}}} endfunction
function! s:is_last_column(lnum, cnum) "{{{
function! s:is_last_column(lnum, cnum)
return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$'
endfunction
function! s:is_last_column(lnum, cnum)
let line = strpart(getline(a:lnum), a:cnum - 1) let line = strpart(getline(a:lnum), a:cnum - 1)
"echomsg "DEBUG is_last_column> ".(line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$')
return line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$' return line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$'
endfunction
endfunction "}}}
function! s:is_first_column(lnum, cnum) "{{{
function! s:is_first_column(lnum, cnum)
let line = strpart(getline(a:lnum), 0, a:cnum - 1) let line = strpart(getline(a:lnum), 0, a:cnum - 1)
"echomsg "DEBUG is_first_column> ".(line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep()) return line =~# '^\s*$' ||
return line =~# '^\s*$' || (line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep()) \ (line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep())
endfunction "}}} endfunction
function! s:count_separators_up(lnum) "{{{
function! s:count_separators_up(lnum)
let lnum = a:lnum - 1 let lnum = a:lnum - 1
while lnum > 1 while lnum > 1
if !s:is_separator(getline(lnum)) if !s:is_separator(getline(lnum))
@ -87,9 +100,10 @@ function! s:count_separators_up(lnum) "{{{
endwhile endwhile
return (a:lnum-lnum) return (a:lnum-lnum)
endfunction "}}} endfunction
function! s:count_separators_down(lnum) "{{{
function! s:count_separators_down(lnum)
let lnum = a:lnum + 1 let lnum = a:lnum + 1
while lnum < line('$') while lnum < line('$')
if !s:is_separator(getline(lnum)) if !s:is_separator(getline(lnum))
@ -99,9 +113,10 @@ function! s:count_separators_down(lnum) "{{{
endwhile endwhile
return (lnum-a:lnum) return (lnum-a:lnum)
endfunction "}}} endfunction
function! s:create_empty_row(cols) "{{{
function! s:create_empty_row(cols)
let row = s:rxSep() let row = s:rxSep()
let cell = " ".s:rxSep() let cell = " ".s:rxSep()
@ -110,9 +125,10 @@ function! s:create_empty_row(cols) "{{{
endfor endfor
return row return row
endfunction "}}} endfunction
function! s:create_row_sep(cols) "{{{
function! s:create_row_sep(cols)
let row = s:rxSep() let row = s:rxSep()
let cell = "---".s:rxSep() let cell = "---".s:rxSep()
@ -121,9 +137,10 @@ function! s:create_row_sep(cols) "{{{
endfor endfor
return row return row
endfunction "}}} endfunction
function! vimwiki#tbl#get_cells(line) "{{{
function! vimwiki#tbl#get_cells(line)
let result = [] let result = []
let cell = '' let cell = ''
let quote = '' let quote = ''
@ -174,13 +191,15 @@ function! vimwiki#tbl#get_cells(line) "{{{
call add(result, vimwiki#u#trim(cell.quote, '|')) call add(result, vimwiki#u#trim(cell.quote, '|'))
endif endif
return result return result
endfunction "}}} endfunction
function! s:col_count(lnum) "{{{
function! s:col_count(lnum)
return len(vimwiki#tbl#get_cells(getline(a:lnum))) return len(vimwiki#tbl#get_cells(getline(a:lnum)))
endfunction "}}} endfunction
function! s:get_indent(lnum) "{{{
function! s:get_indent(lnum)
if !s:is_table(getline(a:lnum)) if !s:is_table(getline(a:lnum))
return return
endif endif
@ -198,9 +217,10 @@ function! s:get_indent(lnum) "{{{
endwhile endwhile
return indent return indent
endfunction " }}} endfunction
function! s:get_rows(lnum) "{{{
function! s:get_rows(lnum)
if !s:is_table(getline(a:lnum)) if !s:is_table(getline(a:lnum))
return return
endif endif
@ -232,14 +252,14 @@ function! s:get_rows(lnum) "{{{
endwhile endwhile
return upper_rows + lower_rows return upper_rows + lower_rows
endfunction "}}} endfunction
function! s:get_cell_aligns(lnum) "{{{
function! s:get_cell_aligns(lnum)
let aligns = {} let aligns = {}
for [lnum, row] in s:get_rows(a:lnum) for [lnum, row] in s:get_rows(a:lnum)
let found_separator = 0 let found_separator = s:is_separator(row)
if s:is_separator(row) if found_separator
let found_separator = 1
let cells = vimwiki#tbl#get_cells(row) let cells = vimwiki#tbl#get_cells(row)
for idx in range(len(cells)) for idx in range(len(cells))
let cell = cells[idx] let cell = cells[idx]
@ -261,9 +281,10 @@ function! s:get_cell_aligns(lnum) "{{{
endfor endfor
endif endif
return aligns return aligns
endfunction "}}} endfunction
function! s:get_cell_max_lens(lnum, ...) "{{{
function! s:get_cell_max_lens(lnum, ...)
let max_lens = {} let max_lens = {}
for [lnum, row] in s:get_rows(a:lnum) for [lnum, row] in s:get_rows(a:lnum)
if s:is_separator(row) if s:is_separator(row)
@ -280,9 +301,10 @@ function! s:get_cell_max_lens(lnum, ...) "{{{
endfor endfor
endfor endfor
return max_lens return max_lens
endfunction "}}} endfunction
function! s:get_aligned_rows(lnum, col1, col2) "{{{
function! s:get_aligned_rows(lnum, col1, col2)
let rows = s:get_rows(a:lnum) let rows = s:get_rows(a:lnum)
let startlnum = rows[0][0] let startlnum = rows[0][0]
let cells = [] let cells = []
@ -301,10 +323,11 @@ function! s:get_aligned_rows(lnum, col1, col2) "{{{
call add(result, [lnum, new_row]) call add(result, [lnum, new_row])
endfor endfor
return result return result
endfunction "}}} endfunction
" Number of the current column. Starts from 0. " Number of the current column. Starts from 0.
function! s:cur_column() "{{{ function! s:cur_column()
let line = getline('.') let line = getline('.')
if !s:is_table(line) if !s:is_table(line)
return -1 return -1
@ -321,12 +344,10 @@ function! s:cur_column() "{{{
endif endif
endwhile endwhile
return col return col
endfunction "}}} endfunction
" }}}
" Format functions {{{ function! s:fmt_cell(cell, max_len, align)
function! s:fmt_cell(cell, max_len, align) "{{{
let cell = ' '.a:cell.' ' let cell = ' '.a:cell.' '
let diff = a:max_len - s:wide_len(a:cell) let diff = a:max_len - s:wide_len(a:cell)
@ -337,13 +358,14 @@ function! s:fmt_cell(cell, max_len, align) "{{{
let cell .= repeat(' ', diff) let cell .= repeat(' ', diff)
elseif a:align == 'right' elseif a:align == 'right'
let cell = repeat(' ',diff).cell let cell = repeat(' ',diff).cell
else else
let cell = repeat(' ',diff/2).cell.repeat(' ',diff-diff/2) let cell = repeat(' ',diff/2).cell.repeat(' ',diff-diff/2)
endif endif
return cell return cell
endfunction "}}} endfunction
function! s:fmt_row(cells, max_lens, aligns, col1, col2) "{{{
function! s:fmt_row(cells, max_lens, aligns, col1, col2)
let new_line = s:rxSep() let new_line = s:rxSep()
for idx in range(len(a:cells)) for idx in range(len(a:cells))
if idx == a:col1 if idx == a:col1
@ -361,9 +383,10 @@ function! s:fmt_row(cells, max_lens, aligns, col1, col2) "{{{
let idx += 1 let idx += 1
endwhile endwhile
return new_line return new_line
endfunction "}}} endfunction
function! s:fmt_cell_sep(max_len, align) "{{{
function! s:fmt_cell_sep(max_len, align)
let cell = '' let cell = ''
if a:max_len == 0 if a:max_len == 0
let cell .= '-' let cell .= '-'
@ -377,9 +400,10 @@ function! s:fmt_cell_sep(max_len, align) "{{{
else else
return ':'.cell.':' return ':'.cell.':'
endif endif
endfunction "}}} endfunction
function! s:fmt_sep(max_lens, aligns, col1, col2) "{{{
function! s:fmt_sep(max_lens, aligns, col1, col2)
let new_line = s:rxSep() let new_line = s:rxSep()
for idx in range(len(a:max_lens)) for idx in range(len(a:max_lens))
if idx == a:col1 if idx == a:col1
@ -390,11 +414,10 @@ function! s:fmt_sep(max_lens, aligns, col1, col2) "{{{
let new_line .= s:fmt_cell_sep(a:max_lens[idx], a:aligns[idx]).s:rxSep() let new_line .= s:fmt_cell_sep(a:max_lens[idx], a:aligns[idx]).s:rxSep()
endfor endfor
return new_line return new_line
endfunction "}}} endfunction
"}}}
" Keyboard functions "{{{
function! s:kbd_create_new_row(cols, goto_first) "{{{ function! s:kbd_create_new_row(cols, goto_first)
let cmd = "\<ESC>o".s:create_empty_row(a:cols) let cmd = "\<ESC>o".s:create_empty_row(a:cols)
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>" let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>"
let cmd .= "\<ESC>0" let cmd .= "\<ESC>0"
@ -407,26 +430,29 @@ function! s:kbd_create_new_row(cols, goto_first) "{{{
let cmd .= "a" let cmd .= "a"
return cmd return cmd
endfunction "}}} endfunction
function! s:kbd_goto_next_row() "{{{
function! s:kbd_goto_next_row()
let cmd = "\<ESC>j" let cmd = "\<ESC>j"
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>" let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>" let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= "a" let cmd .= "a"
return cmd return cmd
endfunction "}}} endfunction
function! s:kbd_goto_prev_row() "{{{
function! s:kbd_goto_prev_row()
let cmd = "\<ESC>k" let cmd = "\<ESC>k"
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>" let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>" let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
let cmd .= "a" let cmd .= "a"
return cmd return cmd
endfunction "}}} endfunction
" Used in s:kbd_goto_next_col " Used in s:kbd_goto_next_col
function! vimwiki#tbl#goto_next_col() "{{{ function! vimwiki#tbl#goto_next_col()
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let newcol = s:get_indent(lnum) let newcol = s:get_indent(lnum)
@ -439,9 +465,10 @@ function! vimwiki#tbl#goto_next_col() "{{{
endfor endfor
let newcol += 2 " +2 == 1 separator + 1 space |<space let newcol += 2 " +2 == 1 separator + 1 space |<space
call vimwiki#u#cursor(lnum, newcol) call vimwiki#u#cursor(lnum, newcol)
endfunction "}}} endfunction
function! s:kbd_goto_next_col(jumpdown) "{{{
function! s:kbd_goto_next_col(jumpdown)
let cmd = "\<ESC>" let cmd = "\<ESC>"
if a:jumpdown if a:jumpdown
let seps = s:count_separators_down(line('.')) let seps = s:count_separators_down(line('.'))
@ -449,10 +476,11 @@ function! s:kbd_goto_next_col(jumpdown) "{{{
endif endif
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a" let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
return cmd return cmd
endfunction "}}} endfunction
" Used in s:kbd_goto_prev_col " Used in s:kbd_goto_prev_col
function! vimwiki#tbl#goto_prev_col() "{{{ function! vimwiki#tbl#goto_prev_col()
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let newcol = s:get_indent(lnum) let newcol = s:get_indent(lnum)
@ -471,9 +499,10 @@ function! vimwiki#tbl#goto_prev_col() "{{{
endfor endfor
let newcol += 2 " +2 == 1 separator + 1 space |<space let newcol += 2 " +2 == 1 separator + 1 space |<space
call vimwiki#u#cursor(lnum, newcol) call vimwiki#u#cursor(lnum, newcol)
endfunction "}}} endfunction
function! s:kbd_goto_prev_col(jumpup) "{{{
function! s:kbd_goto_prev_col(jumpup)
let cmd = "\<ESC>" let cmd = "\<ESC>"
if a:jumpup if a:jumpup
let seps = s:count_separators_up(line('.')) let seps = s:count_separators_up(line('.'))
@ -485,12 +514,10 @@ function! s:kbd_goto_prev_col(jumpup) "{{{
" let cmd .= "a" " let cmd .= "a"
"echomsg "DEBUG kbd_goto_prev_col> ".cmd "echomsg "DEBUG kbd_goto_prev_col> ".cmd
return cmd return cmd
endfunction "}}} endfunction
"}}}
" Global functions {{{ function! vimwiki#tbl#kbd_cr()
function! vimwiki#tbl#kbd_cr() "{{{
let lnum = line('.') let lnum = line('.')
if !s:is_table(getline(lnum)) if !s:is_table(getline(lnum))
return "" return ""
@ -502,9 +529,10 @@ function! vimwiki#tbl#kbd_cr() "{{{
else else
return s:kbd_goto_next_row() return s:kbd_goto_next_row()
endif endif
endfunction "}}} endfunction
function! vimwiki#tbl#kbd_tab() "{{{
function! vimwiki#tbl#kbd_tab()
let lnum = line('.') let lnum = line('.')
if !s:is_table(getline(lnum)) if !s:is_table(getline(lnum))
return "\<Tab>" return "\<Tab>"
@ -518,9 +546,10 @@ function! vimwiki#tbl#kbd_tab() "{{{
return s:kbd_create_new_row(cols, 1) return s:kbd_create_new_row(cols, 1)
endif endif
return s:kbd_goto_next_col(is_sep || last) return s:kbd_goto_next_col(is_sep || last)
endfunction "}}} endfunction
function! vimwiki#tbl#kbd_shift_tab() "{{{
function! vimwiki#tbl#kbd_shift_tab()
let lnum = line('.') let lnum = line('.')
if !s:is_table(getline(lnum)) if !s:is_table(getline(lnum))
return "\<S-Tab>" return "\<S-Tab>"
@ -533,9 +562,10 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{
return "" return ""
endif endif
return s:kbd_goto_prev_col(is_sep || first) return s:kbd_goto_prev_col(is_sep || first)
endfunction "}}} endfunction
function! vimwiki#tbl#format(lnum, ...) "{{{
function! vimwiki#tbl#format(lnum, ...)
if !(&filetype ==? 'vimwiki') if !(&filetype ==? 'vimwiki')
return return
endif endif
@ -563,11 +593,12 @@ function! vimwiki#tbl#format(lnum, ...) "{{{
let row = indentstring.row let row = indentstring.row
call setline(lnum, row) call setline(lnum, row)
endfor endfor
let &tw = s:textwidth
endfunction "}}}
function! vimwiki#tbl#create(...) "{{{ let &tw = s:textwidth
endfunction
function! vimwiki#tbl#create(...)
if a:0 > 1 if a:0 > 1
let cols = a:1 let cols = a:1
let rows = a:2 let rows = a:2
@ -598,19 +629,21 @@ function! vimwiki#tbl#create(...) "{{{
for r in range(rows - 1) for r in range(rows - 1)
call add(lines, row) call add(lines, row)
endfor endfor
call append(line('.'), lines)
endfunction "}}}
function! vimwiki#tbl#align_or_cmd(cmd) "{{{ call append(line('.'), lines)
endfunction
function! vimwiki#tbl#align_or_cmd(cmd)
if s:is_table(getline('.')) if s:is_table(getline('.'))
call vimwiki#tbl#format(line('.')) call vimwiki#tbl#format(line('.'))
else else
exe 'normal! '.a:cmd exe 'normal! '.a:cmd
endif endif
endfunction "}}} endfunction
function! vimwiki#tbl#reset_tw(lnum) "{{{
function! vimwiki#tbl#reset_tw(lnum)
if !(&filetype ==? 'vimwiki') if !(&filetype ==? 'vimwiki')
return return
endif endif
@ -618,14 +651,14 @@ function! vimwiki#tbl#reset_tw(lnum) "{{{
if !s:is_table(line) if !s:is_table(line)
return return
endif endif
let s:textwidth = &tw let s:textwidth = &tw
let &tw = 0 let &tw = 0
endfunction "}}} endfunction
" TODO: move_column_left and move_column_right are good candidates to be
" refactored. " TODO: move_column_left and move_column_right are good candidates to be refactored.
function! vimwiki#tbl#move_column_left() "{{{ function! vimwiki#tbl#move_column_left()
"echomsg "DEBUG move_column_left: " "echomsg "DEBUG move_column_left: "
@ -641,7 +674,7 @@ function! vimwiki#tbl#move_column_left() "{{{
endif endif
if cur_col > 0 if cur_col > 0
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col) call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
call cursor(line('.'), 1) call cursor(line('.'), 1)
let sep = '\('.s:rxSep().'\).\zs' let sep = '\('.s:rxSep().'\).\zs'
@ -651,16 +684,16 @@ function! vimwiki#tbl#move_column_left() "{{{
let mpos = match(line, sep, mpos+1) let mpos = match(line, sep, mpos+1)
if mpos != -1 if mpos != -1
let col += 1 let col += 1
else else
break break
endif endif
endwhile endwhile
endif endif
endfunction
endfunction "}}}
function! vimwiki#tbl#move_column_right() "{{{ function! vimwiki#tbl#move_column_right()
let line = getline('.') let line = getline('.')
@ -674,7 +707,7 @@ function! vimwiki#tbl#move_column_right() "{{{
endif endif
if cur_col < s:col_count(line('.'))-1 if cur_col < s:col_count(line('.'))-1
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1) call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
call cursor(line('.'), 1) call cursor(line('.'), 1)
let sep = '\('.s:rxSep().'\).\zs' let sep = '\('.s:rxSep().'\).\zs'
@ -684,33 +717,35 @@ function! vimwiki#tbl#move_column_right() "{{{
let mpos = match(line, sep, mpos+1) let mpos = match(line, sep, mpos+1)
if mpos != -1 if mpos != -1
let col += 1 let col += 1
else else
break break
endif endif
endwhile endwhile
endif endif
endfunction
endfunction "}}}
function! vimwiki#tbl#get_rows(lnum) "{{{ function! vimwiki#tbl#get_rows(lnum)
return s:get_rows(a:lnum) return s:get_rows(a:lnum)
endfunction "}}} endfunction
function! vimwiki#tbl#is_table(line) "{{{
function! vimwiki#tbl#is_table(line)
return s:is_table(a:line) return s:is_table(a:line)
endfunction "}}} endfunction
function! vimwiki#tbl#is_separator(line) "{{{
function! vimwiki#tbl#is_separator(line)
return s:is_separator(a:line) return s:is_separator(a:line)
endfunction "}}} endfunction
function! vimwiki#tbl#cell_splitter() "{{{
function! vimwiki#tbl#cell_splitter()
return s:cell_splitter() return s:cell_splitter()
endfunction "}}} endfunction
function! vimwiki#tbl#sep_splitter() "{{{
function! vimwiki#tbl#sep_splitter()
return s:sep_splitter() return s:sep_splitter()
endfunction "}}} endfunction
"}}}

View File

@ -1,9 +1,9 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Utility functions " Description: Utility functions
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
function! vimwiki#u#trim(string, ...) "{{{ function! vimwiki#u#trim(string, ...)
let chars = '' let chars = ''
if a:0 > 0 if a:0 > 0
let chars = a:1 let chars = a:1
@ -11,17 +11,20 @@ function! vimwiki#u#trim(string, ...) "{{{
let res = substitute(a:string, '^[[:space:]'.chars.']\+', '', '') let res = substitute(a:string, '^[[:space:]'.chars.']\+', '', '')
let res = substitute(res, '[[:space:]'.chars.']\+$', '', '') let res = substitute(res, '[[:space:]'.chars.']\+$', '', '')
return res return res
endfunction "}}} endfunction
" Builtin cursor doesn't work right with unicode characters. " Builtin cursor doesn't work right with unicode characters.
function! vimwiki#u#cursor(lnum, cnum) "{{{ function! vimwiki#u#cursor(lnum, cnum)
exe a:lnum exe a:lnum
exe 'normal! 0'.a:cnum.'|' exe 'normal! 0'.a:cnum.'|'
endfunction "}}} endfunction
function! vimwiki#u#is_windows() "{{{
function! vimwiki#u#is_windows()
return has("win32") || has("win64") || has("win95") || has("win16") return has("win32") || has("win64") || has("win95") || has("win16")
endfunction "}}} endfunction
function! vimwiki#u#is_macos() function! vimwiki#u#is_macos()
if has("mac") || has("macunix") || has("gui_mac") if has("mac") || has("macunix") || has("gui_mac")
@ -32,32 +35,32 @@ function! vimwiki#u#is_macos()
return os == 'Darwin' || os == 'Mac' return os == 'Darwin' || os == 'Mac'
endfunction endfunction
function! vimwiki#u#count_first_sym(line) "{{{
function! vimwiki#u#count_first_sym(line)
let first_sym = matchstr(a:line, '\S') let first_sym = matchstr(a:line, '\S')
return len(matchstr(a:line, first_sym.'\+')) return len(matchstr(a:line, first_sym.'\+'))
endfunction "}}} endfunction
function! vimwiki#u#escape(string) "{{{
function! vimwiki#u#escape(string)
return escape(a:string, '~.*[]\^$') return escape(a:string, '~.*[]\^$')
endfunction "}}} endfunction
" Load concrete Wiki syntax: sets regexes and templates for headers and links " Load concrete Wiki syntax: sets regexes and templates for headers and links
function vimwiki#u#reload_regexes() "{{{ function vimwiki#u#reload_regexes()
execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim'
endfunction "}}} endfunction
" Load omnipresent Wiki syntax
function vimwiki#u#reload_omni_regexes() "{{{
execute 'runtime! syntax/omnipresent_syntax.vim'
endfunction "}}}
" Load syntax-specific functionality " Load syntax-specific functionality
function vimwiki#u#reload_regexes_custom() "{{{ function vimwiki#u#reload_regexes_custom()
execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'_custom.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim'
endfunction "}}} endfunction
" Backward compatible version of the built-in function shiftwidth() " Backward compatible version of the built-in function shiftwidth()
if exists('*shiftwidth') "{{{ if exists('*shiftwidth')
func vimwiki#u#sw() func vimwiki#u#sw()
return shiftwidth() return shiftwidth()
endfunc endfunc
@ -65,4 +68,5 @@ else
func vimwiki#u#sw() func vimwiki#u#sw()
return &sw return &sw
endfunc endfunc
endif "}}} endif

711
autoload/vimwiki/vars.vim Normal file
View File

@ -0,0 +1,711 @@
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
" Home: https://github.com/vimwiki/vimwiki/
" ------------------------------------------------------------------------------------------------
" This file provides functions to manage the various state variables which are needed during a
" Vimwiki session.
" They consist of:
"
" - global variables. These are stored in the dict g:vimwiki_global_vars. They consist mainly of
" global user variables and syntax stuff which is the same for every syntax.
"
" - wiki-local variables. They are stored in g:vimwiki_wikilocal_vars which is a list of
" dictionaries. One dict for every registered wiki. The last dictionary contains default values
" (used for temporary wikis).
"
" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and
" other stuff which is needed for highlighting.
"
" - buffer-local variables. They are stored as buffer variables directly (b:foo)
" As a developer, you should, if possible, only use the get_ and set_ functions for these types of
" variables, not the underlying dicts!
" ------------------------------------------------------------------------------------------------
function! s:populate_global_variables()
let g:vimwiki_global_vars = {
\ 'CJK_length': 0,
\ 'auto_chdir': 0,
\ 'autowriteall': 1,
\ 'conceallevel': 2,
\ 'diary_months':
\ {
\ 1: 'January', 2: 'February', 3: 'March',
\ 4: 'April', 5: 'May', 6: 'June',
\ 7: 'July', 8: 'August', 9: 'September',
\ 10: 'October', 11: 'November', 12: 'December'
\ },
\ 'dir_link': '',
\ 'ext2syntax': {},
\ 'folding': '',
\ 'global_ext': 1,
\ 'hl_cb_checked': 0,
\ 'hl_headers': 0,
\ 'html_header_numbering': 0,
\ 'html_header_numbering_sym': '',
\ 'list_ignore_newline': 1,
\ 'text_ignore_newline': 1,
\ 'listsyms': ' .oOX',
\ 'listsym_rejected': '-',
\ 'map_prefix': '<Leader>w',
\ 'menu': 'Vimwiki',
\ 'table_auto_fmt': 1,
\ 'table_mappings': 1,
\ 'toc_header': 'Contents',
\ 'url_maxsave': 15,
\ 'use_calendar': 1,
\ 'use_mouse': 0,
\ 'user_htmls': '',
\ 'valid_html_tags': 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em',
\ 'w32_dir_enc': '',
\ }
" copy the user's settings from variables of the form g:vimwiki_<option> into the dict
" g:vimwiki_global_vars (or set a default value)
for key in keys(g:vimwiki_global_vars)
if exists('g:vimwiki_'.key)
let g:vimwiki_global_vars[key] = g:vimwiki_{key}
endif
endfor
" non-configurable global variables:
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
" able to <leader>w<leader>w without opening any vimwiki file first
let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|')
let g:vimwiki_global_vars.web_schemes1 = join(['http', 'https', 'file', 'ftp', 'gopher',
\ 'telnet', 'nntp', 'ldap', 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh',
\ 'git', 'ssh', 'fish', 'sftp'], '\|')
let web_schemes2 =
\ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|')
let g:vimwiki_global_vars.rxSchemes = '\%('.
\ g:vimwiki_global_vars.schemes . '\|'.
\ g:vimwiki_global_vars.web_schemes1 . '\|'.
\ web_schemes2 .
\ '\)'
" match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
" http://tools.ietf.org/html/rfc3986
let rxWebProtocols =
\ '\%('.
\ '\%('.
\ '\%('.g:vimwiki_global_vars.web_schemes1 . '\):'.
\ '\%(//\)'.
\ '\)'.
\ '\|'.
\ '\%('.web_schemes2.'\):'.
\ '\)'
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
let wikilink_prefix = '[['
let wikilink_suffix = ']]'
let wikilink_separator = '|'
let g:vimwiki_global_vars.rx_wikilink_prefix = vimwiki#u#escape(wikilink_prefix)
let g:vimwiki_global_vars.rx_wikilink_suffix = vimwiki#u#escape(wikilink_suffix)
let g:vimwiki_global_vars.rx_wikilink_separator = vimwiki#u#escape(wikilink_separator)
" templates for the creation of wiki links
" [[URL]]
let g:vimwiki_global_vars.WikiLinkTemplate1 = wikilink_prefix . '__LinkUrl__'. wikilink_suffix
" [[URL|DESCRIPTION]]
let g:vimwiki_global_vars.WikiLinkTemplate2 = wikilink_prefix . '__LinkUrl__'. wikilink_separator
\ . '__LinkDescription__' . wikilink_suffix
let valid_chars = '[^\\\]]'
let g:vimwiki_global_vars.rxWikiLinkUrl = valid_chars.'\{-}'
let g:vimwiki_global_vars.rxWikiLinkDescr = valid_chars.'\{-}'
" this regexp defines what can form a link when the user presses <CR> in the
" buffer (and not on a link) to create a link
" basically, it's Ascii alphanumeric characters plus #|./@-_~ plus all
" non-Ascii characters
let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]\+'
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix .
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator
let g:vimwiki_global_vars.rx_wikilink_suffix1 = g:vimwiki_global_vars.rx_wikilink_suffix
let g:vimwiki_global_vars.rxWikiInclPrefix = '{{'
let g:vimwiki_global_vars.rxWikiInclSuffix = '}}'
let g:vimwiki_global_vars.rxWikiInclSeparator = '|'
" '{{__LinkUrl__}}'
let g:vimwiki_global_vars.WikiInclTemplate1 = g:vimwiki_global_vars.rxWikiInclPrefix
\ .'__LinkUrl__'. g:vimwiki_global_vars.rxWikiInclSuffix
" '{{__LinkUrl____LinkDescription__}}'
let g:vimwiki_global_vars.WikiInclTemplate2 = g:vimwiki_global_vars.rxWikiInclPrefix
\ . '__LinkUrl__' . g:vimwiki_global_vars.rxWikiInclSeparator . '__LinkDescription__'
\ . g:vimwiki_global_vars.rxWikiInclSuffix
let valid_chars = '[^\\\}]'
let g:vimwiki_global_vars.rxWikiInclUrl = valid_chars.'\{-}'
let g:vimwiki_global_vars.rxWikiInclArg = valid_chars.'\{-}'
let g:vimwiki_global_vars.rxWikiInclArgs = '\%('. g:vimwiki_global_vars.rxWikiInclSeparator.
\ g:vimwiki_global_vars.rxWikiInclArg. '\)'.'\{-}'
" *. {{URL}[{...}]} - i.e. {{URL}}, {{URL|ARG1}}, {{URL|ARG1|ARG2}}, etc.
" *a) match {{URL}[{...}]}
let g:vimwiki_global_vars.rxWikiIncl = g:vimwiki_global_vars.rxWikiInclPrefix.
\ g:vimwiki_global_vars.rxWikiInclUrl.
\ g:vimwiki_global_vars.rxWikiInclArgs. g:vimwiki_global_vars.rxWikiInclSuffix
" *b) match URL within {{URL}[{...}]}
let g:vimwiki_global_vars.rxWikiInclMatchUrl = g:vimwiki_global_vars.rxWikiInclPrefix.
\ '\zs'. g:vimwiki_global_vars.rxWikiInclUrl . '\ze'.
\ g:vimwiki_global_vars.rxWikiInclArgs . g:vimwiki_global_vars.rxWikiInclSuffix
let g:vimwiki_global_vars.rxWikiInclPrefix1 = g:vimwiki_global_vars.rxWikiInclPrefix.
\ g:vimwiki_global_vars.rxWikiInclUrl . g:vimwiki_global_vars.rxWikiInclSeparator
let g:vimwiki_global_vars.rxWikiInclSuffix1 = g:vimwiki_global_vars.rxWikiInclArgs.
\ g:vimwiki_global_vars.rxWikiInclSuffix
let g:vimwiki_global_vars.rxTodo = '\C\<\%(TODO\|DONE\|STARTED\|FIXME\|FIXED\|XXX\)\>'
" default colors when headers of different levels are highlighted differently
" not making it yet another option; needed by ColorScheme autocommand
let g:vimwiki_global_vars.hcolor_guifg_light = ['#aa5858', '#507030', '#1030a0', '#103040'
\ , '#505050', '#636363']
let g:vimwiki_global_vars.hcolor_ctermfg_light = ['DarkRed', 'DarkGreen', 'DarkBlue', 'Black'
\ , 'Black', 'Black']
let g:vimwiki_global_vars.hcolor_guifg_dark = ['#e08090', '#80e090', '#6090e0', '#c0c0f0'
\ , '#e0e0f0', '#f0f0f0']
let g:vimwiki_global_vars.hcolor_ctermfg_dark = ['Red', 'Green', 'Blue', 'White', 'White'
\ , 'White']
endfunction
function! s:populate_wikilocal_options()
let default_values = {
\ 'auto_export': 0,
\ 'auto_tags': 0,
\ 'auto_toc': 0,
\ 'automatic_nested_syntaxes': 1,
\ 'css_name': 'style.css',
\ 'custom_wiki2html': '',
\ 'custom_wiki2html_args': '',
\ 'diary_header': 'Diary',
\ 'diary_index': 'diary',
\ 'diary_rel_path': 'diary/',
\ 'diary_sort': 'desc',
\ 'ext': '.wiki',
\ 'index': 'index',
\ 'list_margin': -1,
\ 'maxhi': 0,
\ 'nested_syntaxes': {},
\ 'path': '~/vimwiki/',
\ 'path_html': '',
\ 'syntax': 'default',
\ 'template_default': 'default',
\ 'template_ext': '.tpl',
\ 'template_path': '~/vimwiki/templates/',
\ }
let g:vimwiki_wikilocal_vars = []
let default_wiki_settings = {}
for key in keys(default_values)
if exists('g:vimwiki_'.key)
let default_wiki_settings[key] = g:vimwiki_{key}
else
let default_wiki_settings[key] = default_values[key]
endif
endfor
" set the wiki-local variables according to g:vimwiki_list (or the default settings)
if exists('g:vimwiki_list')
for users_wiki_settings in g:vimwiki_list
let new_wiki_settings = {}
for key in keys(default_values)
if has_key(users_wiki_settings, key)
let new_wiki_settings[key] = users_wiki_settings[key]
elseif exists('g:vimwiki_'.key)
let new_wiki_settings[key] = g:vimwiki_{key}
else
let new_wiki_settings[key] = default_values[key]
endif
endfor
let new_wiki_settings.is_temporary_wiki = 0
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
endfor
else
" if the user hasn't registered any wiki, we register one wiki using the default values
let new_wiki_settings = deepcopy(default_wiki_settings)
let new_wiki_settings.is_temporary_wiki = 0
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
endif
" default values for temporary wikis
let temporary_wiki_settings = deepcopy(default_wiki_settings)
let temporary_wiki_settings.is_temporary_wiki = 1
call add(g:vimwiki_wikilocal_vars, temporary_wiki_settings)
call s:validate_settings()
endfunction
function! s:validate_settings()
for wiki_settings in g:vimwiki_wikilocal_vars
let wiki_settings['path'] = s:normalize_path(wiki_settings['path'])
let path_html = wiki_settings['path_html']
if !empty(path_html)
let wiki_settings['path_html'] = s:normalize_path(path_html)
else
let wiki_settings['path_html'] = s:normalize_path(
\ substitute(wiki_settings['path'], '[/\\]\+$', '', '').'_html/')
endif
let wiki_settings['template_path'] = s:normalize_path(wiki_settings['template_path'])
let wiki_settings['diary_rel_path'] = s:normalize_path(wiki_settings['diary_rel_path'])
endfor
endfunction
function! s:normalize_path(path)
" trim trailing / and \ because otherwise resolve() doesn't work quite right
let path = substitute(a:path, '[/\\]\+$', '', '')
if path !~# '^scp:'
return resolve(expand(path)).'/'
else
return path.'/'
endif
endfunction
function! vimwiki#vars#populate_syntax_vars(syntax)
if !exists('g:vimwiki_syntax_variables')
let g:vimwiki_syntax_variables = {}
endif
if has_key(g:vimwiki_syntax_variables, a:syntax)
return
endif
let g:vimwiki_syntax_variables[a:syntax] = {}
execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim'
" generic stuff
let header_symbol = g:vimwiki_syntax_variables[a:syntax].rxH
if g:vimwiki_syntax_variables[a:syntax].symH
" symmetric headers
for i in range(1,6)
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
\ repeat(header_symbol, i).' __Header__ '.repeat(header_symbol, i)
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
\ .header_symbol.'\{'.i.'}\s*$'
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
\ .header_symbol.'\{'.i.'}\s*$'
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
\ .header_symbol.'\{1,'.i.'}\s*$'
endfor
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$'
else
" asymmetric
for i in range(1,6)
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
\ repeat(header_symbol, i).' __Header__'
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$'
endfor
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*\ze$'
endif
let g:vimwiki_syntax_variables[a:syntax].rxPreStart =
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreStart
let g:vimwiki_syntax_variables[a:syntax].rxPreEnd =
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreEnd.'\s*$'
let g:vimwiki_syntax_variables[a:syntax].rxMathStart =
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathStart
let g:vimwiki_syntax_variables[a:syntax].rxMathEnd =
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathEnd.'\s*$'
" list stuff
let g:vimwiki_syntax_variables[a:syntax].rx_bullet_chars =
\ '['.join(g:vimwiki_syntax_variables[a:syntax].bullet_types, '').']\+'
let g:vimwiki_syntax_variables[a:syntax].multiple_bullet_chars =
\ g:vimwiki_syntax_variables[a:syntax].recurring_bullets
\ ? g:vimwiki_syntax_variables[a:syntax].bullet_types : []
let g:vimwiki_syntax_variables[a:syntax].number_kinds = []
let g:vimwiki_syntax_variables[a:syntax].number_divisors = ''
for i in g:vimwiki_syntax_variables[a:syntax].number_types
call add(g:vimwiki_syntax_variables[a:syntax].number_kinds, i[0])
let g:vimwiki_syntax_variables[a:syntax].number_divisors .= vimwiki#u#escape(i[1])
endfor
let char_to_rx = {'1': '\d\+', 'i': '[ivxlcdm]\+', 'I': '[IVXLCDM]\+',
\ 'a': '\l\{1,2}', 'A': '\u\{1,2}'}
"create regexp for bulleted list items
if !empty(g:vimwiki_syntax_variables[a:syntax].bullet_types)
let g:vimwiki_syntax_variables[a:syntax].rxListBullet =
\ join( map(g:vimwiki_syntax_variables[a:syntax].bullet_types,
\'vimwiki#u#escape(v:val).'
\ .'repeat("\\+", g:vimwiki_syntax_variables[a:syntax].recurring_bullets)'
\ ) , '\|')
else
"regex that matches nothing
let g:vimwiki_syntax_variables[a:syntax].rxListBullet = '$^'
endif
"create regex for numbered list items
if !empty(g:vimwiki_syntax_variables[a:syntax].number_types)
let g:vimwiki_syntax_variables[a:syntax].rxListNumber = '\C\%('
for type in g:vimwiki_syntax_variables[a:syntax].number_types[:-2]
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .= char_to_rx[type[0]] .
\ vimwiki#u#escape(type[1]) . '\|'
endfor
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .=
\ char_to_rx[g:vimwiki_syntax_variables[a:syntax].number_types[-1][0]].
\ vimwiki#u#escape(g:vimwiki_syntax_variables[a:syntax].number_types[-1][1]) . '\)'
else
"regex that matches nothing
let g:vimwiki_syntax_variables[a:syntax].rxListNumber = '$^'
endif
"the user can set the listsyms as string, but vimwiki needs a list
let g:vimwiki_syntax_variables[a:syntax].listsyms_list =
\ split(vimwiki#vars#get_global('listsyms'), '\zs')
if match(vimwiki#vars#get_global('listsyms'), vimwiki#vars#get_global('listsym_rejected')) != -1
echomsg 'Vimwiki Warning: the value of g:vimwiki_listsym_rejected ('''
\ . vimwiki#vars#get_global('listsym_rejected')
\ . ''') must not be a part of g:vimwiki_listsyms (''' .
\ . vimwiki#vars#get_global('listsyms') . ''')'
endif
let g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB =
\ '^\s*\%(\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\|\('
\ .g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\)\s'
let g:vimwiki_syntax_variables[a:syntax].rxListItem =
\ g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB
\ . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms')
\ . vimwiki#vars#get_global('listsym_rejected').']\)\]\s\)\?'
if g:vimwiki_syntax_variables[a:syntax].recurring_bullets
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
\ '^\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\s\+\[['
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\%('
\ .g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\).*\|^$\|\s.*\)\)*'
else
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
\ '^\(\s*\)\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\|'
\ . g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\s\+\[['
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
endif
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
let g:vimwiki_syntax_variables[a:syntax].rxWeblink =
\ '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '\S*'
" 0a) match URL within URL
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchUrl =
\ g:vimwiki_syntax_variables[a:syntax].rxWeblink
" 0b) match DESCRIPTION within URL
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchDescr = ''
" template for matching all wiki links with a given target file
let g:vimwiki_syntax_variables[a:syntax].WikiLinkMatchUrlTemplate =
\ g:vimwiki_global_vars.rx_wikilink_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ g:vimwiki_global_vars.rx_wikilink_suffix .
\ '\|' .
\ g:vimwiki_global_vars.rx_wikilink_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ g:vimwiki_global_vars.rx_wikilink_separator .
\ '.*' .
\ g:vimwiki_global_vars.rx_wikilink_suffix
" a) match [[URL|DESCRIPTION]]
let g:vimwiki_syntax_variables[a:syntax].rxWikiLink = g:vimwiki_global_vars.rx_wikilink_prefix.
\ g:vimwiki_global_vars.rxWikiLinkUrl.'\%('.g:vimwiki_global_vars.rx_wikilink_separator.
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
let g:vimwiki_syntax_variables[a:syntax].rxAnyLink =
\ g:vimwiki_syntax_variables[a:syntax].rxWikiLink.'\|'.
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_syntax_variables[a:syntax].rxWeblink
" b) match URL within [[URL|DESCRIPTION]]
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchUrl =
\ g:vimwiki_global_vars.rx_wikilink_prefix . '\zs'. g:vimwiki_global_vars.rxWikiLinkUrl
\ .'\ze\%('. g:vimwiki_global_vars.rx_wikilink_separator
\ . g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchDescr =
\ g:vimwiki_global_vars.rx_wikilink_prefix . g:vimwiki_global_vars.rxWikiLinkUrl
\ . g:vimwiki_global_vars.rx_wikilink_separator.'\%(\zs'
\ . g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'
\ . g:vimwiki_global_vars.rx_wikilink_suffix
if a:syntax ==# 'markdown'
call s:populate_extra_markdown_vars()
endif
endfunction
function! s:populate_extra_markdown_vars()
let mkd_syntax = g:vimwiki_syntax_variables['markdown']
" 0a) match [[URL|DESCRIPTION]]
let mkd_syntax.rxWikiLink0 = mkd_syntax.rxWikiLink
" 0b) match URL within [[URL|DESCRIPTION]]
let mkd_syntax.rxWikiLink0MatchUrl = mkd_syntax.rxWikiLinkMatchUrl
" 0c) match DESCRIPTION within [[URL|DESCRIPTION]]
let mkd_syntax.rxWikiLink0MatchDescr = mkd_syntax.rxWikiLinkMatchDescr
let wikilink_md_prefix = '['
let wikilink_md_suffix = ']'
let wikilink_md_separator = ']['
let rx_wikilink_md_separator = vimwiki#u#escape(wikilink_md_separator)
let mkd_syntax.rx_wikilink_md_prefix = vimwiki#u#escape(wikilink_md_prefix)
let mkd_syntax.rx_wikilink_md_suffix = vimwiki#u#escape(wikilink_md_suffix)
" [URL][]
let mkd_syntax.WikiLink1Template1 = wikilink_md_prefix . '__LinkUrl__'.
\ wikilink_md_separator. wikilink_md_suffix
" [DESCRIPTION][URL]
let mkd_syntax.WikiLink1Template2 = wikilink_md_prefix. '__LinkDescription__'.
\ wikilink_md_separator. '__LinkUrl__'. wikilink_md_suffix
let mkd_syntax.WikiLinkMatchUrlTemplate .=
\ '\|' .
\ mkd_syntax.rx_wikilink_md_prefix .
\ '.*' .
\ rx_wikilink_md_separator .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ mkd_syntax.rx_wikilink_md_suffix .
\ '\|' .
\ mkd_syntax.rx_wikilink_md_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ rx_wikilink_md_separator .
\ mkd_syntax.rx_wikilink_md_suffix
let valid_chars = '[^\\\[\]]'
let mkd_syntax.rxWikiLink1Url = valid_chars.'\{-}'
let mkd_syntax.rxWikiLink1Descr = valid_chars.'\{-}'
let mkd_syntax.rxWikiLink1InvalidPrefix = '[\]\[]\@<!'
let mkd_syntax.rxWikiLink1InvalidSuffix = '[\]\[]\@!'
let mkd_syntax.rx_wikilink_md_prefix = mkd_syntax.rxWikiLink1InvalidPrefix.
\ mkd_syntax.rx_wikilink_md_prefix
let mkd_syntax.rx_wikilink_md_suffix = mkd_syntax.rx_wikilink_md_suffix.
\ mkd_syntax.rxWikiLink1InvalidSuffix
" 1. match [URL][], [DESCRIPTION][URL]
let mkd_syntax.rxWikiLink1 = mkd_syntax.rx_wikilink_md_prefix.
\ mkd_syntax.rxWikiLink1Url. rx_wikilink_md_separator.
\ mkd_syntax.rx_wikilink_md_suffix.
\ '\|'. mkd_syntax.rx_wikilink_md_prefix.
\ mkd_syntax.rxWikiLink1Descr . rx_wikilink_md_separator.
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
" 2. match URL within [URL][], [DESCRIPTION][URL]
let mkd_syntax.rxWikiLink1MatchUrl = mkd_syntax.rx_wikilink_md_prefix.
\ '\zs'. mkd_syntax.rxWikiLink1Url. '\ze'. rx_wikilink_md_separator.
\ mkd_syntax.rx_wikilink_md_suffix.
\ '\|'. mkd_syntax.rx_wikilink_md_prefix.
\ mkd_syntax.rxWikiLink1Descr. rx_wikilink_md_separator.
\ '\zs'. mkd_syntax.rxWikiLink1Url. '\ze'. mkd_syntax.rx_wikilink_md_suffix
" 3. match DESCRIPTION within [DESCRIPTION][URL]
let mkd_syntax.rxWikiLink1MatchDescr = mkd_syntax.rx_wikilink_md_prefix.
\ '\zs'. mkd_syntax.rxWikiLink1Descr.'\ze'. rx_wikilink_md_separator.
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
let mkd_syntax.rxWikiLink1Prefix1 = mkd_syntax.rx_wikilink_md_prefix
let mkd_syntax.rxWikiLink1Suffix1 = rx_wikilink_md_separator.
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
" 1. match ANY wikilink
let mkd_syntax.rxWikiLink = mkd_syntax.rxWikiLink0 . '\|' . mkd_syntax.rxWikiLink1
" 2. match URL within ANY wikilink
let mkd_syntax.rxWikiLinkMatchUrl = mkd_syntax.rxWikiLink0MatchUrl . '\|' .
\ mkd_syntax.rxWikiLink1MatchUrl
" 3. match DESCRIPTION within ANY wikilink
let mkd_syntax.rxWikiLinkMatchDescr = mkd_syntax.rxWikiLink0MatchDescr . '\|' .
\ mkd_syntax.rxWikiLink1MatchDescr
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
let mkd_syntax.rxWeblink0 = mkd_syntax.rxWeblink
" 0a) match URL within URL
let mkd_syntax.rxWeblinkMatchUrl0 = mkd_syntax.rxWeblinkMatchUrl
" 0b) match DESCRIPTION within URL
let mkd_syntax.rxWeblinkMatchDescr0 = mkd_syntax.rxWeblinkMatchDescr
let mkd_syntax.rxWeblink1Prefix = '['
let mkd_syntax.rxWeblink1Suffix = ')'
let mkd_syntax.rxWeblink1Separator = ']('
" [DESCRIPTION](URL)
let mkd_syntax.Weblink1Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'.
\ mkd_syntax.rxWeblink1Suffix
let valid_chars = '[^\\]'
let mkd_syntax.rxWeblink1Prefix = vimwiki#u#escape(mkd_syntax.rxWeblink1Prefix)
let mkd_syntax.rxWeblink1Suffix = vimwiki#u#escape(mkd_syntax.rxWeblink1Suffix)
let mkd_syntax.rxWeblink1Separator = vimwiki#u#escape(mkd_syntax.rxWeblink1Separator)
let mkd_syntax.rxWeblink1Url = valid_chars.'\{-}'
let mkd_syntax.rxWeblink1Descr = valid_chars.'\{-}'
" 1. [DESCRIPTION](URL)
" 1a) match [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1 = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Suffix
" 1b) match URL within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchUrl = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Descr. mkd_syntax.rxWeblink1Separator.
\ '\zs' . mkd_syntax.rxWeblink1Url . '\ze' . mkd_syntax.rxWeblink1Suffix
" 1c) match DESCRIPTION within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchDescr = mkd_syntax.rxWeblink1Prefix.
\ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1Suffix
" TODO: image links too !!
let mkd_syntax.rxWeblink1Prefix1 = mkd_syntax.rxWeblink1Prefix
let mkd_syntax.rxWeblink1Suffix1 = mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1Suffix
" *a) match ANY weblink
let mkd_syntax.rxWeblink = ''.
\ mkd_syntax.rxWeblink1.'\|'.
\ mkd_syntax.rxWeblink0
" *b) match URL within ANY weblink
let mkd_syntax.rxWeblinkMatchUrl = ''.
\ mkd_syntax.rxWeblink1MatchUrl.'\|'.
\ mkd_syntax.rxWeblinkMatchUrl0
" *c) match DESCRIPTION within ANY weblink
let mkd_syntax.rxWeblinkMatchDescr = ''.
\ mkd_syntax.rxWeblink1MatchDescr.'\|'.
\ mkd_syntax.rxWeblinkMatchDescr0
let mkd_syntax.rxAnyLink = mkd_syntax.rxWikiLink.'\|'.
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.mkd_syntax.rxWeblink
let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ mkd_syntax.rxWeblink0
let mkd_syntax.rxMkdRefMatchDescr =
\ '\[\zs'.g:vimwiki_global_vars.rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'. mkd_syntax.rxWeblink0
let mkd_syntax.rxMkdRefMatchUrl =
\ '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
\ mkd_syntax.rxWeblink0.'\ze'
endfunction
function! vimwiki#vars#init()
call s:populate_global_variables()
call s:populate_wikilocal_options()
endfunction
function! vimwiki#vars#get_syntaxlocal(key, ...)
if a:0
let syntax = a:1
else
let syntax = vimwiki#vars#get_wikilocal('syntax')
endif
if !exists('g:vimwiki_syntax_variables') || !has_key(g:vimwiki_syntax_variables, syntax)
call vimwiki#vars#populate_syntax_vars(syntax)
endif
return g:vimwiki_syntax_variables[syntax][a:key]
endfunction
" Get a variable for the buffer we are currently in or for the given buffer (number or name).
" Populate the variable, if it doesn't exist.
function! vimwiki#vars#get_bufferlocal(key, ...)
let buffer = a:0 ? a:1 : '%'
let value = getbufvar(buffer, 'vimwiki_'.a:key, '/\/\')
if type(value) != 1 || value !=# '/\/\'
return value
elseif a:key ==# 'wiki_nr'
call setbufvar(buffer, 'vimwiki_wiki_nr', vimwiki#base#find_wiki(expand('%:p')))
elseif a:key ==# 'subdir'
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
elseif a:key ==# 'invsubdir'
let subdir = vimwiki#vars#get_bufferlocal('subdir')
call setbufvar(buffer, 'vimwiki_invsubdir', vimwiki#base#invsubdir(subdir))
elseif a:key ==# 'existing_wikifiles'
call setbufvar(buffer, 'vimwiki_existing_wikifiles',
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1))
elseif a:key ==# 'existing_wikidirs'
call setbufvar(buffer, 'vimwiki_existing_wikidirs',
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
elseif a:key ==# 'prev_link'
call setbufvar(buffer, 'vimwiki_prev_link', [])
elseif a:key ==# 'markdown_refs'
call setbufvar(buffer, 'vimwiki_markdown_refs', vimwiki#markdown_base#scan_reflinks())
else
echoerr 'Vimwiki Error: unknown buffer variable ' . string(a:key)
endif
return getbufvar(buffer, 'vimwiki_'.a:key)
endfunction
function! vimwiki#vars#set_bufferlocal(key, value, ...)
let buffer = a:0 ? a:1 : '%'
call setbufvar(buffer, 'vimwiki_' . a:key, a:value)
endfunction
function! vimwiki#vars#get_global(key)
return g:vimwiki_global_vars[a:key]
endfunction
" the second argument can be a wiki number. When absent, the wiki of the currently active buffer is
" used
function! vimwiki#vars#get_wikilocal(key, ...)
if a:0
return g:vimwiki_wikilocal_vars[a:1][a:key]
else
return g:vimwiki_wikilocal_vars[vimwiki#vars#get_bufferlocal('wiki_nr')][a:key]
endif
endfunction
function! vimwiki#vars#get_wikilocal_default(key)
return g:vimwiki_wikilocal_vars[-1][a:key]
endfunction
function! vimwiki#vars#set_wikilocal(key, value, wiki_nr)
if a:wiki_nr == len(g:vimwiki_wikilocal_vars) - 1
call insert(g:vimwiki_wikilocal_vars, {}, -1)
endif
let g:vimwiki_wikilocal_vars[a:wiki_nr][a:key] = a:value
endfunction
function! vimwiki#vars#add_temporary_wiki(settings)
let new_temp_wiki_settings = copy(g:vimwiki_wikilocal_vars[-1])
for [key, value] in items(a:settings)
let new_temp_wiki_settings[key] = value
endfor
call insert(g:vimwiki_wikilocal_vars, new_temp_wiki_settings, -1)
call s:validate_settings()
endfunction
" number of registered wikis + temporary
function! vimwiki#vars#number_of_wikis()
return len(g:vimwiki_wikilocal_vars) - 1
endfunction

View File

@ -9,7 +9,7 @@
|___| |___| |_| |_||__| |__||___| |___| |_||___| ~ |___| |___| |_| |_||__| |__||___| |___| |_||___| ~
Version: 2.3 Version: 2.4
============================================================================== ==============================================================================
CONTENTS *vimwiki* CONTENTS *vimwiki*
@ -47,10 +47,11 @@ CONTENTS *vimwiki*
12.2. Temporary Wiki |vimwiki-temporary-wiki| 12.2. Temporary Wiki |vimwiki-temporary-wiki|
12.3. Per-Wiki Options |vimwiki-local-options| 12.3. Per-Wiki Options |vimwiki-local-options|
12.4. Global Options |vimwiki-global-options| 12.4. Global Options |vimwiki-global-options|
13. Contributing |vimwiki-contributing| 13. Getting help |vimwiki-help|
14. Development |vimwiki-development| 14. Contributing & Bug reports |vimwiki-contributing|
15. Changelog |vimwiki-changelog| 15. Development |vimwiki-development|
16. License |vimwiki-license| 16. Changelog |vimwiki-changelog|
17. License |vimwiki-license|
============================================================================== ==============================================================================
@ -213,6 +214,22 @@ See also |:VimwikiTabMakeDiaryNote|
< <
See also |:VimwikiMakeYesterdayDiaryNote| See also |:VimwikiMakeYesterdayDiaryNote|
[count]<Leader>w<Leader>m or <Plug>VimwikiMakeTomorrowDiaryNote
Open diary wiki-file for tomorrow of the [count]'s wiki.
<Leader>w<Leader>m opens diary wiki-file for tomorrow in the first
wiki from |g:vimwiki_list|.
1<Leader>w<Leader>m as above opens diary wiki-file for tomorrow in
the first wiki from |g:vimwiki_list|.
2<Leader>w<Leader>m opens diary wiki-file for tomorrow in the second
wiki from |g:vimwiki_list|.
3<Leader>w<Leader>m opens diary wiki-file for tomorrow in the third
wiki from |g:vimwiki_list|.
etc.
To remap: >
:nmap <Leader>dm <Plug>VimwikiMakeTomorrowDiaryNote
<
See also |:VimwikiMakeTomorrowDiaryNote|
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
3.2. Local mappings 3.2. Local mappings
@ -222,7 +239,7 @@ To remap one of these keys, either put it in your .vimrc like this >
or, the better way, put it in a file .vim/ftplugin/vimwiki.vim like this > or, the better way, put it in a file .vim/ftplugin/vimwiki.vim like this >
:nmap <silent><buffer> <Leader>wc <Plug>Vimwiki2HTML :nmap <silent><buffer> <Leader>wc <Plug>Vimwiki2HTML
The latter has the advantage that the mapping is local to viwiki buffers in The latter has the advantage that the mapping is local to Vimwiki buffers in
every case. every case.
Also note that some keys work in normal mode as well as in visual mode. If you Also note that some keys work in normal mode as well as in visual mode. If you
@ -324,6 +341,34 @@ NORMAL MODE *vimwiki-local-mappings*
- Remove header level. - Remove header level.
To remap: > To remap: >
:nmap -- <Plug>VimwikiRemoveHeaderLevel :nmap -- <Plug>VimwikiRemoveHeaderLevel
<
*vimwiki_[[*
[[ Go to the previous header in the buffer.
To remap: >
:nmap <- <Plug>VimwikiGoToPrevHeader
<
*vimwiki_]]*
]] Go to the next header in the buffer.
To remap: >
:nmap -> <Plug>VimwikiGoToNextHeader
<
*vimwiki_[=*
[= Go to the previous header which has the same level as
the header the cursor is currently under.
To remap: >
:nmap <= <Plug>VimwikiGoToPrevSiblingHeader
<
*vimwiki_]=*
]= Go to the next header which has the same level as the
header the cursor is currently under.
To remap: >
:nmap => <Plug>VimwikiGoToNextSiblingHeader
<
*vimwiki_]u* *vimwiki_[u*
]u [u Go one level up -- that is, to the parent header of
the header the cursor is currently under.
To remap: >
:nmap -^ <Plug>VimwikiGoToParentHeader
< <
*vimwiki_+* *vimwiki_+*
+ Create and/or decorate links. Depending on the + Create and/or decorate links. Depending on the
@ -455,6 +500,13 @@ gLI Change the symbol of the current list to
To remap: > To remap: >
noremap glo :VimwikiChangeSymbolTo I)<CR> noremap glo :VimwikiChangeSymbolTo I)<CR>
noremap glO :VimwikiChangeSymbolInListTo I)<CR> noremap glO :VimwikiChangeSymbolInListTo I)<CR>
<
*vimwiki_glx*
glx Toggle checkbox of a list item disabled/off.
Maps to |:VimwikiToggleRejectedListItem|.
See |vimwiki-todo-lists|.
To remap: >
:map <Leader>tx <Plug>VimwikiToggleRejectedListItem
< <
*vimwiki_gqq* *vimwiki_gww* *vimwiki_gqq* *vimwiki_gww*
gqq Format table. If you made some changes to a table gqq Format table. If you made some changes to a table
@ -557,12 +609,22 @@ INSERT MODE *vimwiki-list-mappings*
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
3.3. Text objects *vimwiki-text-objects* 3.3. Text objects *vimwiki-text-objects*
ah A section segment (the area between two consecutive ah A header including its content up to the next header.
headings) including trailing empty lines. ih The content under a header (like 'ah', but excluding
ih A section segment without trailing empty lines. the header itself and trailing empty lines).
You can type 'vah' to select a section segment with its contents or 'dah' to aH A header including all of its subheaders. When [count]
delete it or 'yah' to yank it or 'cah' to change it. is 2, include the parent header, when [count] is 3,
the grandparent and so on.
iH Like 'aH', but excluding the header itself and
trailing empty lines.
Examples:
- type 'cih' to change the content under the current header
- 'daH' deletes an entire header plus its content including the content of all
of its subheaders
- 'v2aH' selects the parent header of the header the cursor is under plus all
of the content of all of its subheaders
a\ A cell in a table. a\ A cell in a table.
i\ An inner cell in a table. i\ An inner cell in a table.
@ -600,6 +662,8 @@ il A single list item.
*:VimwikiMakeYesterdayDiaryNote* *:VimwikiMakeYesterdayDiaryNote*
Open diary wiki-file for yesterday of the current wiki. Open diary wiki-file for yesterday of the current wiki.
*:VimwikiMakeTomorrowDiaryNote*
Open diary wiki-file for tomorrow of the current wiki.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
4.2. Local commands *vimwiki-local-commands* 4.2. Local commands *vimwiki-local-commands*
@ -613,12 +677,24 @@ Vimwiki file.
*:VimwikiGoBackLink* *:VimwikiGoBackLink*
Go back to the wiki page you came from. Go back to the wiki page you came from.
*:VimwikiSplitLink* *:VimwikiSplitLink* [reuse] [move_cursor]
Split and follow wiki link (create target wiki page if needed). Split and follow wiki link (create target wiki page if needed).
*:VimwikiVSplitLink* If the argument 'reuse' is given and nonzero, the link is opened in a
possibly existing split window instead of making a new split.
If 'move_cursor' is given and nonzero, the cursor moves to the window with
the opened link, otherwise, it stays in the window with the link.
*:VimwikiVSplitLink* [reuse] [move_cursor]
Vertical split and follow wiki link (create target wiki page if needed). Vertical split and follow wiki link (create target wiki page if needed).
If the argument 'reuse' is given and nonzero, the link is opened in a
possibly existing split window instead of making a new split.
If 'move_cursor' is given and nonzero, the cursor moves to the window with
the opened link, otherwise, it stays in the window with the link.
*:VimwikiTabnewLink* *:VimwikiTabnewLink*
Follow wiki link in a new tab (create target wiki page if needed). Follow wiki link in a new tab (create target wiki page if needed).
@ -656,6 +732,10 @@ Vimwiki file.
Toggle checkbox of a list item on/off. Toggle checkbox of a list item on/off.
See |vimwiki-todo-lists|. See |vimwiki-todo-lists|.
*:VimwikiToggleRejectedListItem*
Toggle checkbox of a list item disabled/off.
See |vimwiki-todo-lists|.
*:VimwikiListChangeLevel* CMD *:VimwikiListChangeLevel* CMD
Change the nesting level, or symbol, for a single-line list item. Change the nesting level, or symbol, for a single-line list item.
CMD may be ">>" or "<<" to change the indentation of the item, or CMD may be ">>" or "<<" to change the indentation of the item, or
@ -669,6 +749,11 @@ Vimwiki file.
To display next match use |:lnext| command. To display next match use |:lnext| command.
To display previous match use |:lprevious| command. To display previous match use |:lprevious| command.
Hint: this feature is simply a wrapper around |:lvimgrep|. For a
description of how the pattern can look like, see |:vimgrep|. For example,
to do a case insensitive search, use >
:VWS /\cpattern/
*:VimwikiBacklinks* *:VimwikiBacklinks*
*:VWB* *:VWB*
Search for wikilinks to the current wiki page in all files of current Search for wikilinks to the current wiki page in all files of current
@ -756,35 +841,6 @@ Vimwiki file.
are specified, outputs all tags. To make this command work properly, make are specified, outputs all tags. To make this command work properly, make
sure the tags have been built (see |vimwiki-build-tags|). sure the tags have been built (see |vimwiki-build-tags|).
------------------------------------------------------------------------------
4.3. Functions *vimwiki-functions*
Functions to interact with Vimwiki. (It's intended that most commands will be
replaced with corresponding function calls in the future.)
Warning: this is currently unstable and likely to change.
To map them to a key, use >
nnoremap <C-K> :call vimwiki#base#function_name(arg1, arg2)<CR>
<
*vimwiki-follow_link*
vimwiki#base#follow_link({split}, {reuse}, {move_cursor})
Open the link under the cursor. {split} can have the following values:
'nosplit' open the link in the current window
'vsplit' open in a vertically split window
'hsplit' open in a horizontally split window
'tab' open in a new tab
If {reuse} is 1 and {split} one of 'vsplit' or 'hsplit', open the link in
a possibly existing split window instead of making a new split.
If {move_cursor} is 1 the cursor moves to the window or tab with the
opened link, otherwise, it stays in the window or tab with the link.
For example, <CR> is per default mapped to
vimwiki#base#follow_link('nosplit', 0, 1)
============================================================================== ==============================================================================
5. Wiki syntax *vimwiki-syntax* 5. Wiki syntax *vimwiki-syntax*
@ -821,6 +877,8 @@ is decorated: >
super^script^ super^script^
sub,,script,, sub,,script,,
Furthermore, there are a number of words which are highlighted extra flashy:
TODO, DONE, STARTED, FIXME, FIXED, XXX.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
5.2. Links *vimwiki-syntax-links* 5.2. Links *vimwiki-syntax-links*
@ -857,7 +915,7 @@ which opens up a popup menu with all the wiki files starting with "ind".
When |vimwiki-option-maxhi| equals 1, a distinct highlighting style is used to When |vimwiki-option-maxhi| equals 1, a distinct highlighting style is used to
identify wikilinks whose targets are not found. identify wikilinks whose targets are not found.
Interwiki:~ Interwiki~
If you maintain more than one wiki, you can create interwiki links between If you maintain more than one wiki, you can create interwiki links between
them by adding a numbered prefix "wikiX:" in front of a link: > them by adding a numbered prefix "wikiX:" in front of a link: >
@ -868,15 +926,11 @@ or: >
The number behind "wiki" is in the range 0..N-1 and identifies the destination The number behind "wiki" is in the range 0..N-1 and identifies the destination
wiki in |g:vimwiki_list|. wiki in |g:vimwiki_list|.
Diary:~ Diary~
The "diary:" scheme is used to concisely link to diary entries: > The "diary:" scheme is used to link to diary entries: >
[[diary:2012-03-05]] [[diary:2012-03-05]]
This scheme precludes explicit inclusion of |vimwiki-option-diary_rel_path|,
and is most useful on subwiki pages to avoid links such as: >
[[../../diary/2012-03-05]]
Anchors~ Anchors~
A wikilink, interwiki link or diary link can be followed by a '#' and the name A wikilink, interwiki link or diary link can be followed by a '#' and the name
@ -1233,14 +1287,9 @@ LaTeX code).
Note: the highlighting in Vim is automatic. For the rendering in HTML, you Note: the highlighting in Vim is automatic. For the rendering in HTML, you
have two alternative options: have two alternative options:
1. using the MathJax server for rendering (needs internet connection). 1. installing MathJax locally (Recommended: faster, no internet required).
Add to your HTML template the following line: Choose a folder on your hard drive and save MathJax in it. Then add to your
HTML template the following line:
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
2. installing MathJax locally (faster, no internet required). Choose a
folder on your hard drive and save MathJax in it. Then add to your HTML
template the following line:
<script type="text/javascript" src="<mathjax_folder>/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/javascript" src="<mathjax_folder>/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
@ -1255,6 +1304,11 @@ template folder. For instance, a sensible folder structure could be:
In this case, <mathjax_folder> would be "../mathjax" (without quotes). In this case, <mathjax_folder> would be "../mathjax" (without quotes).
2. Loading MathJax from a CDN-server (needs internet connection).
Add to your HTML template the following line:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/config/TeX-AMS-MML_HTMLorMML.js"></script>
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
5.9. Blockquotes *vimwiki-syntax-blockquotes* 5.9. Blockquotes *vimwiki-syntax-blockquotes*
@ -1621,6 +1675,9 @@ Use gl<Space> (see |vimwiki_gl<Space>|) to remove a single checkbox and
gL<Space> (see |vimwiki_gL<Space>|) to remove all checkboxes of the list the gL<Space> (see |vimwiki_gL<Space>|) to remove all checkboxes of the list the
cursor is in. cursor is in.
You can mark an item as rejected ("won't do") with
|vimwiki_glx|. A rejected item will not influence the status of its parents.
============================================================================== ==============================================================================
9. Tables *vimwiki-tables* 9. Tables *vimwiki-tables*
@ -1793,6 +1850,12 @@ as described in |vimwiki-register-wiki|, or may be registered on the fly as
described in |vimwiki-temporary-wiki|. For a list of per-wiki options, see described in |vimwiki-temporary-wiki|. For a list of per-wiki options, see
|vimwiki-local-options|. |vimwiki-local-options|.
A note for Vim power users:
If you have an elaborated Vim setup, where you e.g. load plugins
conditionally, make sure the settings are set before Vimwiki loads (that is,
before plugin/vimwiki.vim is sourced). If this is not possible, try this
command after the Vimwiki settings are (re-) set: >
:call vimwiki#vars#init()
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
12.1 Registered Wiki *g:vimwiki_list* *vimwiki-register-wiki* 12.1 Registered Wiki *g:vimwiki_list* *vimwiki-register-wiki*
@ -2201,15 +2264,15 @@ be located at https://github.com/vimwiki-backup/vimwiki/issues/384
To use the internal wiki2html converter, use an empty string (the default). To use the internal wiki2html converter, use an empty string (the default).
vimwiki-option-custom_wiki2html_args *vimwiki-option-custom_wiki2html_args*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
Key Default value~ Key Default value~
custom_wiki2html_args '' custom_wiki2html_args ''
Description Description~
If a custom script is called with |vimwiki-option-custom_wiki2html|, additional If a custom script is called with |vimwiki-option-custom_wiki2html|, additional
parameters can be passed by setting them using 'custom_wiki2html_args' in parameters can be passed using this option: >
|g:vimwiki_list|. let g:vimwiki_list = [{'path': '~/path/', 'custom_wiki2html_args': 'stuff'}]
*vimwiki-option-list_margin* *vimwiki-option-list_margin*
@ -2354,6 +2417,19 @@ You can set it to some more fancy symbols like this:
let g:vimwiki_listsyms = '✗○◐●✓' let g:vimwiki_listsyms = '✗○◐●✓'
------------------------------------------------------------------------------
*g:vimwiki_listsym_rejected*
Character that is used to show that an item of a todo list will not be done.
Default value is '-'.
The character used here must not be part of |g:vimwiki_listsyms|.
You can set it to a more fancy symbol like this:
>
let g:vimwiki_listsym_rejected = '✗'
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*g:vimwiki_use_mouse* *g:vimwiki_use_mouse*
@ -2388,6 +2464,8 @@ Limitations:
- 'list' is intended to work with lists nicely indented with 'shiftwidth'. - 'list' is intended to work with lists nicely indented with 'shiftwidth'.
- 'syntax' is only available for the default syntax so far. - 'syntax' is only available for the default syntax so far.
The options above can be suffixed with ':quick' (e.g.: 'expr:quick') in order
to use some workarounds to make folds work faster.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*g:vimwiki_list_ignore_newline* *g:vimwiki_list_ignore_newline*
@ -2717,8 +2795,12 @@ Default: 2
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*g:vimwiki_autowriteall* *g:vimwiki_autowriteall*
In Vim 'autowriteall' is a global setting. With g:vimwiki_autowriteall Vimwiki Automatically save a modified wiki buffer when switching wiki pages. Has the
makes it local to its buffers. same effect like setting the Vim option 'autowriteall', but it works for wiki
files only, while the Vim option is global.
Hint: if you're just annoyed that you have to save files manually to switch
wiki pages, consider setting the Vim option 'hidden' which makes that modified
files don't need to be saved.
Value Description~ Value Description~
0 autowriteall is off 0 autowriteall is off
@ -2810,9 +2892,17 @@ Value Description~
Default: 0 Default: 0
==============================================================================
13. Getting help *vimwiki-help*
For questions, discussions, praise or rants there is a mailing list:
https://groups.google.com/forum/#!forum/vimwiki
Also, there is the IRC channel #vimwiki on Freenode which can be accessed via
webchat: https://webchat.freenode.net/?channels=#vimwiki
============================================================================== ==============================================================================
13. Contributing *vimwiki-contributing* 14. Contributing & Bug reports *vimwiki-contributing*
Your help in making Vimwiki better is really appreciated! Your help in making Vimwiki better is really appreciated!
Any help, whether it is a spelling correction or a code snippet to patch -- Any help, whether it is a spelling correction or a code snippet to patch --
@ -2827,12 +2917,8 @@ Issues can be filed at https://github.com/vimwiki/vimwiki/issues/.
If you want to provide a pull request on GitHub, please start from the dev If you want to provide a pull request on GitHub, please start from the dev
branch, not from the master branch. branch, not from the master branch.
For questions, discussions, praise or rants there is a mailing list:
https://groups.google.com/forum/#!forum/vimwiki
============================================================================== ==============================================================================
14. Development *vimwiki-development* 15. Development *vimwiki-development*
Homepage: http://vimwiki.github.io/ Homepage: http://vimwiki.github.io/
Github: https://github.com/vimwiki/vimwiki/ Github: https://github.com/vimwiki/vimwiki/
@ -2863,10 +2949,37 @@ Contributors and their Github usernames in roughly chronological order:
- @wangzq - @wangzq
- Jinzhou Zhang (@lotabout) - Jinzhou Zhang (@lotabout)
- Michael Riley (@optik-aper) - Michael Riley (@optik-aper)
- Irfan Sharif (@irfansharif)
- John Conroy (@jconroy77)
- Christian Rondeau (@christianrondeau)
- Alex Thorne (@thornecc)
- Shafqat Bhuiyan (@priomsrb)
- Bradley Cicenas (@bcicen)
- Michael Thessel (@MichaelThessel)
- Michael F. Schönitzer (@nudin)
- @sqlwwx
- Guilherme Salazar (@salazar)
- Daniel Trnka (@trnila)
- Yuchen Pei (@ycpei)
- @maqiv
- @dpc
- Drew Hays (@Dru89)
- Daniel Etrata (@danetrata)
- Keith Haber (@kjhaber)
- @beuerle
- Silvio Ricardo Cordeiro (@silvioricardoc)
- @blyoa
- Jonathan McElroy (@jonathanmcelroy)
- @PetrusZ
- Brian Gianforcaro (@bgianfo)
- Ben Burrill (@benburrill)
- Zhuang Ma (@mzlogin)
- Huy Le (@huynle)
- Nick Borden (@hcwndbyw)
============================================================================== ==============================================================================
15. Changelog *vimwiki-changelog* 16. Changelog *vimwiki-changelog*
Issue numbers starting with '#' are issues from Issue numbers starting with '#' are issues from
@ -2875,14 +2988,61 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
https://github.com/vimwiki-backup/vimwiki/issues. https://github.com/vimwiki-backup/vimwiki/issues.
2.4 (not yet released)~
New:~
* Add the option |g:vimwiki_text_ignore_newline|.
* |g:vimwiki_listsyms| can have fewer or more than 5 symbols.
* glx on a list item marks a checkbox as won't do, see |vimwiki_glx|.
* Add the option |g:vimwiki_listsym_rejected| to set the character used
for won't-do list items.
* gln and glp change the "done" status of a checkbox, see |vimwiki_gln|.
* |:VimwikiSplitLink| and |:VimwikiVSplitLink| can now reuse an existing
split window and not move the cursor.
* Add 'aH' and 'iH' text objects, see |vimwiki-text-objects|.
* Add the keys |vimwiki_[[|, |vimwiki_]]|, |vimwiki_[=|, |vimwiki_]=| and
|vimwiki_]u| for navigating between headers.
* Add the command |:VimwikiMakeTomorrowDiaryNote|.
* |g:vimwiki_folding| has a new option 'custom'.
* Add the ':quick' option for faster folding, see |g:vimwiki_folding|.
* Add the %date placeholder, see |vimwiki-date|.
* Add the option |vimwiki-option-custom_wiki2html_args|.
* Add support for HTML-style comments when using markdown syntax.
Removed:~
* Remove the undocumented and buggy command :VimwikiReadLocalOptions
which allowed to store Vimwiki related settings in a local file.
* Remove the undocumented command :VimwikiPrintWikiState.
* For complicated reasons, Vimwiki doesn't clean up its settings anymore
if you change the filetype of a wiki buffer.
Fixed:~
* Make |vimwiki-option-automatic_nested_syntaxes| work also for markdown.
* Issue #236: Highlight math blocks as TeX math, not TeX.
* Issue #264: Don't overwrite mappings to i_<CR> from other plugins.
* Fix an error where <BS> sometimes didn't work under Windows.
* Issue #302: |:VimwikiDiaryGenerateLinks| had issues with markdown.
* Issue #445: Better handling of |'autowriteall'| and |'hidden'|.
* Improve 'ah' and 'ih' text objects, see |vimwiki-text-objects|.
* Allow opening of links using Powershell.
* Allow any visual mode to be used with |vimwiki_+|.
* Markdown syntax for |vimwiki-toc| is used, when appropriate.
* Wikis can now be in subfolders of other wikis.
* Issue #482: |:VimwikiMakeDiaryNote| now uses the diary of the current wiki.
* Opening the diary and wikis from the menu works correctly now.
* Issue #497: Make |:VimwikiMakeDiaryNote| work outside a wiki buffer.
* Use markdown syntax in the diary when appropriate.
* Various other minor fixes.
2.3 (2016-03-31)~ 2.3 (2016-03-31)~
New: New:~
* Add |:VimwikiMakeYesterdayDiaryNote| command * Add |:VimwikiMakeYesterdayDiaryNote| command
* Issue #128: add option |vimwiki-option-automatic_nested_syntaxes| * Issue #128: add option |vimwiki-option-automatic_nested_syntaxes|
* Issue #192: Sort links in the list generated by |:VimwikiGenerateTags| * Issue #192: Sort links in the list generated by |:VimwikiGenerateTags|
Fixed: Fixed:~
* Issue #176: Fix issue when the wiki path contains spaces * Issue #176: Fix issue when the wiki path contains spaces
* Also look for tags in wiki files in subdirectories * Also look for tags in wiki files in subdirectories
* Locate the .tags file correctly on Windows * Locate the .tags file correctly on Windows
@ -3108,12 +3268,13 @@ http://code.google.com/p/vimwiki/issues/list
* First public version. * First public version.
============================================================================== ==============================================================================
16. License *vimwiki-license* 17. License *vimwiki-license*
The MIT Licence The MIT License
http://www.opensource.org/licenses/mit-license.php http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2008-2010 Maxim Kim Copyright (c) 2008-2010 Maxim Kim
2013-2017 Daniel Schemala
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,4 +1,4 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki filetype plugin file " Vimwiki filetype plugin file
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
@ -7,35 +7,22 @@ if exists("b:did_ftplugin")
endif endif
let b:did_ftplugin = 1 " Don't load another plugin for this buffer let b:did_ftplugin = 1 " Don't load another plugin for this buffer
call vimwiki#u#reload_regexes()
call vimwiki#u#reload_omni_regexes()
" UNDO list {{{
" Reset the following options to undo this plugin.
let b:undo_ftplugin = "setlocal ".
\ "suffixesadd< isfname< formatlistpat< ".
\ "formatoptions< foldtext< ".
\ "foldmethod< foldexpr< commentstring< "
" UNDO }}}
" MISC STUFF {{{
setlocal commentstring=%%%s setlocal commentstring=%%%s
if g:vimwiki_conceallevel && exists("+conceallevel") if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &l:conceallevel = g:vimwiki_conceallevel let &l:conceallevel = vimwiki#vars#get_global('conceallevel')
endif endif
" GOTO FILE: gf {{{ " This is for GOTO FILE: gf
execute 'setlocal suffixesadd='.VimwikiGet('ext') execute 'setlocal suffixesadd='.vimwiki#vars#get_wikilocal('ext')
setlocal isfname-=[,] setlocal isfname-=[,]
" gf}}}
exe "setlocal tags+=" . escape(vimwiki#tags#metadata_file_path(), ' \|"') exe "setlocal tags+=" . escape(vimwiki#tags#metadata_file_path(), ' \|"')
" MISC }}}
" COMPLETION {{{
function! Complete_wikifiles(findstart, base) function! Complete_wikifiles(findstart, base)
if a:findstart == 1 if a:findstart == 1
let column = col('.')-2 let column = col('.')-2
@ -45,7 +32,7 @@ function! Complete_wikifiles(findstart, base)
let s:line_context = '[' let s:line_context = '['
return startoflink return startoflink
endif endif
if VimwikiGet('syntax') ==? 'markdown' if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown'
let startofinlinelink = match(line, '\[.*\](\zs[^)]*$') let startofinlinelink = match(line, '\[.*\](\zs[^)]*$')
if startofinlinelink != -1 if startofinlinelink != -1
let s:line_context = '[' let s:line_context = '['
@ -61,7 +48,7 @@ function! Complete_wikifiles(findstart, base)
return -1 return -1
else else
" Completion works for wikilinks/anchors, and for tags. s:line_content " Completion works for wikilinks/anchors, and for tags. s:line_content
" tells us, which string came before a:base. There seems to be no easier " tells us which string came before a:base. There seems to be no easier
" solution, because calling col('.') here returns garbage. " solution, because calling col('.') here returns garbage.
if s:line_context == '' if s:line_context == ''
return [] return []
@ -78,7 +65,7 @@ function! Complete_wikifiles(findstart, base)
if a:base =~# '^wiki\d:' if a:base =~# '^wiki\d:'
let wikinumber = eval(matchstr(a:base, '^wiki\zs\d')) let wikinumber = eval(matchstr(a:base, '^wiki\zs\d'))
if wikinumber >= len(g:vimwiki_list) if wikinumber >= vimwiki#vars#number_of_wikis()
return [] return []
endif endif
let prefix = matchstr(a:base, '^wiki\d:\zs.*') let prefix = matchstr(a:base, '^wiki\d:\zs.*')
@ -88,7 +75,7 @@ function! Complete_wikifiles(findstart, base)
let prefix = matchstr(a:base, '^diary:\zs.*') let prefix = matchstr(a:base, '^diary:\zs.*')
let scheme = matchstr(a:base, '^diary:\ze') let scheme = matchstr(a:base, '^diary:\ze')
else " current wiki else " current wiki
let wikinumber = g:vimwiki_current_idx let wikinumber = vimwiki#vars#get_bufferlocal('wiki_nr')
let prefix = a:base let prefix = a:base
let scheme = '' let scheme = ''
endif endif
@ -109,7 +96,7 @@ function! Complete_wikifiles(findstart, base)
let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0] let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0]
let link_infos = vimwiki#base#resolve_link(given_wikifile.'#') let link_infos = vimwiki#base#resolve_link(given_wikifile.'#')
let wikifile = link_infos.filename let wikifile = link_infos.filename
let syntax = VimwikiGet('syntax', link_infos.index) let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index)
let anchors = vimwiki#base#get_anchors(wikifile, syntax) let anchors = vimwiki#base#get_anchors(wikifile, syntax)
let filtered_anchors = [] let filtered_anchors = []
@ -126,9 +113,9 @@ function! Complete_wikifiles(findstart, base)
endfunction endfunction
setlocal omnifunc=Complete_wikifiles setlocal omnifunc=Complete_wikifiles
" COMPLETION }}}
" LIST STUFF {{{
" settings necessary for the automatic formatting of lists " settings necessary for the automatic formatting of lists
setlocal autoindent setlocal autoindent
setlocal nosmartindent setlocal nosmartindent
@ -140,8 +127,7 @@ setlocal formatoptions-=o
setlocal formatoptions-=2 setlocal formatoptions-=2
setlocal formatoptions+=n setlocal formatoptions+=n
"Create 'formatlistpat' let &formatlistpat = vimwiki#vars#get_syntaxlocal('rxListItem')
let &formatlistpat = g:vimwiki_rxListItem
if !empty(&langmap) if !empty(&langmap)
" Valid only if langmap is a comma separated pairs of chars " Valid only if langmap is a comma separated pairs of chars
@ -156,50 +142,54 @@ if !empty(&langmap)
endif endif
endif endif
" LIST STUFF }}}
" FOLDING {{{
" Folding list items {{{ " ------------------------------------------------
function! VimwikiFoldListLevel(lnum) "{{{ " Folding stuff
" ------------------------------------------------
function! VimwikiFoldListLevel(lnum)
return vimwiki#lst#fold_level(a:lnum) return vimwiki#lst#fold_level(a:lnum)
endfunction "}}} endfunction
" Folding list items }}}
" Folding sections and code blocks {{{
function! VimwikiFoldLevel(lnum) "{{{ function! VimwikiFoldLevel(lnum)
let line = getline(a:lnum) let line = getline(a:lnum)
" Header/section folding... " Header/section folding...
if line =~# g:vimwiki_rxHeader if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
return '>'.vimwiki#u#count_first_sym(line) return '>'.vimwiki#u#count_first_sym(line)
" Code block folding... " Code block folding...
elseif line =~# g:vimwiki_rxPreStart elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
return 'a1' return 'a1'
elseif line =~# g:vimwiki_rxPreEnd elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
return 's1' return 's1'
else else
return "=" return "="
endif endif
endfunction
endfunction "}}}
" Constants used by VimwikiFoldText {{{ " Constants used by VimwikiFoldText
" use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space " use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space
let s:ellipsis = (&enc ==? 'utf-8') ? "\u2026" : "..." let s:ellipsis = (&enc ==? 'utf-8') ? "\u2026" : "..."
let s:ell_len = strlen(s:ellipsis) let s:ell_len = strlen(s:ellipsis)
let s:newline = (&enc ==? 'utf-8') ? "\u21b2 " : " " let s:newline = (&enc ==? 'utf-8') ? "\u21b2 " : " "
let s:tolerance = 5 let s:tolerance = 5
" }}}
function! s:shorten_text_simple(text, len) "{{{ unused
" unused
function! s:shorten_text_simple(text, len)
let spare_len = a:len - len(a:text) let spare_len = a:len - len(a:text)
return (spare_len>=0) ? [a:text,spare_len] : [a:text[0:a:len].s:ellipsis, -1] return (spare_len>=0) ? [a:text,spare_len] : [a:text[0:a:len].s:ellipsis, -1]
endfunction "}}} endfunction
" s:shorten_text(text, len) = [string, spare] with "spare" = len-strlen(string) " s:shorten_text(text, len) = [string, spare] with "spare" = len-strlen(string)
" for long enough "text", the string's length is within s:tolerance of "len" " for long enough "text", the string's length is within s:tolerance of "len"
" (so that -s:tolerance <= spare <= s:tolerance, "string" ends with s:ellipsis) " (so that -s:tolerance <= spare <= s:tolerance, "string" ends with s:ellipsis)
function! s:shorten_text(text, len) "{{{ returns [string, spare] function! s:shorten_text(text, len)
" returns [string, spare]
" strlen() returns lenght in bytes, not in characters, so we'll have to do a " strlen() returns lenght in bytes, not in characters, so we'll have to do a
" trick here -- replace all non-spaces with dot, calculate lengths and " trick here -- replace all non-spaces with dot, calculate lengths and
" indexes on it, then use original string to break at selected index. " indexes on it, then use original string to break at selected index.
@ -212,16 +202,16 @@ function! s:shorten_text(text, len) "{{{ returns [string, spare]
let newlen = a:len - s:ell_len let newlen = a:len - s:ell_len
let idx = strridx(text_pattern, ' ', newlen + s:tolerance) let idx = strridx(text_pattern, ' ', newlen + s:tolerance)
let break_idx = (idx + s:tolerance >= newlen) ? idx : newlen let break_idx = (idx + s:tolerance >= newlen) ? idx : newlen
return [matchstr(a:text, '\m^.\{'.break_idx.'\}').s:ellipsis, return [matchstr(a:text, '\m^.\{'.break_idx.'\}').s:ellipsis, newlen - break_idx]
\ newlen - break_idx] endfunction
endfunction "}}}
function! VimwikiFoldText() "{{{
function! VimwikiFoldText()
let line = getline(v:foldstart) let line = getline(v:foldstart)
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '') let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
let fold_len = v:foldend - v:foldstart + 1 let fold_len = v:foldend - v:foldstart + 1
let len_text = ' ['.fold_len.'] ' let len_text = ' ['.fold_len.'] '
if line !~# g:vimwiki_rxPreStart if line !~# vimwiki#vars#get_syntaxlocal('rxPreStart')
let [main_text, spare_len] = s:shorten_text(main_text, 50) let [main_text, spare_len] = s:shorten_text(main_text, 50)
return main_text.len_text return main_text.len_text
else else
@ -236,27 +226,30 @@ function! VimwikiFoldText() "{{{
endif endif
return main_text.len_text.content_text return main_text.len_text.content_text
endif endif
endfunction "}}} endfunction
" Folding sections and code blocks }}}
" FOLDING }}}
" COMMANDS {{{
" ------------------------------------------------
" Commands
" ------------------------------------------------
command! -buffer Vimwiki2HTML command! -buffer Vimwiki2HTML
\ if filewritable(expand('%')) | silent noautocmd w | endif \ if filewritable(expand('%')) | silent noautocmd w | endif
\ <bar> \ <bar>
\ let res = vimwiki#html#Wiki2HTML(expand(VimwikiGet('path_html')), \ let res = vimwiki#html#Wiki2HTML(expand(vimwiki#vars#get_wikilocal('path_html')),
\ expand('%')) \ expand('%'))
\ <bar> \ <bar>
\ if res != '' | echo 'Vimwiki: HTML conversion is done, output: '.expand(VimwikiGet('path_html')) | endif \ if res != '' | echo 'Vimwiki: HTML conversion is done, output: '
\ . expand(vimwiki#vars#get_wikilocal('path_html')) | endif
command! -buffer Vimwiki2HTMLBrowse command! -buffer Vimwiki2HTMLBrowse
\ if filewritable(expand('%')) | silent noautocmd w | endif \ if filewritable(expand('%')) | silent noautocmd w | endif
\ <bar> \ <bar>
\ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML( \ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML(
\ expand(VimwikiGet('path_html')), \ expand(vimwiki#vars#get_wikilocal('path_html')),
\ expand('%'))) \ expand('%')))
command! -buffer VimwikiAll2HTML command! -buffer VimwikiAll2HTML
\ call vimwiki#html#WikiAll2HTML(expand(VimwikiGet('path_html'))) \ call vimwiki#html#WikiAll2HTML(expand(vimwiki#vars#get_wikilocal('path_html')))
command! -buffer VimwikiTOC call vimwiki#base#table_of_contents(1) command! -buffer VimwikiTOC call vimwiki#base#table_of_contents(1)
@ -266,8 +259,8 @@ command! -buffer VimwikiDeleteLink call vimwiki#base#delete_link()
command! -buffer VimwikiRenameLink call vimwiki#base#rename_link() command! -buffer VimwikiRenameLink call vimwiki#base#rename_link()
command! -buffer VimwikiFollowLink call vimwiki#base#follow_link('nosplit', 0, 1) command! -buffer VimwikiFollowLink call vimwiki#base#follow_link('nosplit', 0, 1)
command! -buffer VimwikiGoBackLink call vimwiki#base#go_back_link() command! -buffer VimwikiGoBackLink call vimwiki#base#go_back_link()
command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('hsplit', 0, 1) command! -buffer -nargs=* VimwikiSplitLink call vimwiki#base#follow_link('hsplit', <f-args>)
command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit', 0, 1) command! -buffer -nargs=* VimwikiVSplitLink call vimwiki#base#follow_link('vsplit', <f-args>)
command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link(<f-args>) command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link(<f-args>)
@ -279,10 +272,10 @@ command! -buffer -nargs=0 VimwikiBacklinks call vimwiki#base#backlinks()
command! -buffer -nargs=0 VWB call vimwiki#base#backlinks() command! -buffer -nargs=0 VWB call vimwiki#base#backlinks()
exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep <args> '. exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep <args> '.
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') \ escape(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ')
exe 'command! -buffer -nargs=* VWS lvimgrep <args> '. exe 'command! -buffer -nargs=* VWS lvimgrep <args> '.
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') \ escape(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ')
command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped
\ VimwikiGoto call vimwiki#base#goto(<f-args>) \ VimwikiGoto call vimwiki#base#goto(<f-args>)
@ -291,13 +284,19 @@ command! -buffer VimwikiCheckLinks call vimwiki#base#check_links()
" list commands " list commands
command! -buffer -nargs=+ VimwikiReturn call <SID>CR(<f-args>) command! -buffer -nargs=+ VimwikiReturn call <SID>CR(<f-args>)
command! -buffer -range -nargs=1 VimwikiChangeSymbolTo call vimwiki#lst#change_marker(<line1>, <line2>, <f-args>, 'n') command! -buffer -range -nargs=1 VimwikiChangeSymbolTo
command! -buffer -range -nargs=1 VimwikiListChangeSymbolI call vimwiki#lst#change_marker(<line1>, <line2>, <f-args>, 'i') \ call vimwiki#lst#change_marker(<line1>, <line2>, <f-args>, 'n')
command! -buffer -nargs=1 VimwikiChangeSymbolInListTo call vimwiki#lst#change_marker_in_list(<f-args>) command! -buffer -range -nargs=1 VimwikiListChangeSymbolI
\ call vimwiki#lst#change_marker(<line1>, <line2>, <f-args>, 'i')
command! -buffer -nargs=1 VimwikiChangeSymbolInListTo
\ call vimwiki#lst#change_marker_in_list(<f-args>)
command! -buffer -range VimwikiToggleListItem call vimwiki#lst#toggle_cb(<line1>, <line2>) command! -buffer -range VimwikiToggleListItem call vimwiki#lst#toggle_cb(<line1>, <line2>)
command! -buffer -range VimwikiToggleRejectedListItem
\ call vimwiki#lst#toggle_rejected_cb(<line1>, <line2>)
command! -buffer -range VimwikiIncrementListItem call vimwiki#lst#increment_cb(<line1>, <line2>) command! -buffer -range VimwikiIncrementListItem call vimwiki#lst#increment_cb(<line1>, <line2>)
command! -buffer -range VimwikiDecrementListItem call vimwiki#lst#decrement_cb(<line1>, <line2>) command! -buffer -range VimwikiDecrementListItem call vimwiki#lst#decrement_cb(<line1>, <line2>)
command! -buffer -range -nargs=+ VimwikiListChangeLvl call vimwiki#lst#change_level(<line1>, <line2>, <f-args>) command! -buffer -range -nargs=+ VimwikiListChangeLvl
\ call vimwiki#lst#change_level(<line1>, <line2>, <f-args>)
command! -buffer -range VimwikiRemoveSingleCB call vimwiki#lst#remove_cb(<line1>, <line2>) command! -buffer -range VimwikiRemoveSingleCB call vimwiki#lst#remove_cb(<line1>, <line2>)
command! -buffer VimwikiRemoveCBInList call vimwiki#lst#remove_cb_in_list() command! -buffer VimwikiRemoveCBInList call vimwiki#lst#remove_cb_in_list()
command! -buffer VimwikiRenumberList call vimwiki#lst#adjust_numbered_list() command! -buffer VimwikiRenumberList call vimwiki#lst#adjust_numbered_list()
@ -316,20 +315,25 @@ command! -buffer VimwikiDiaryNextDay call vimwiki#diary#goto_next_day()
command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day() command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day()
" tags commands " tags commands
command! -buffer -bang command! -buffer -bang VimwikiRebuildTags call vimwiki#tags#update_tags(1, '<bang>')
\ VimwikiRebuildTags call vimwiki#tags#update_tags(1, '<bang>')
command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
\ VimwikiSearchTags VimwikiSearch /:<args>:/ \ VimwikiSearchTags VimwikiSearch /:<args>:/
command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
\ VimwikiGenerateTags call vimwiki#tags#generate_tags(<f-args>) \ VimwikiGenerateTags call vimwiki#tags#generate_tags(<f-args>)
" COMMANDS }}} command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p'))
" KEYBINDINGS {{{
if g:vimwiki_use_mouse " ------------------------------------------------
" Keybindings
" ------------------------------------------------
if vimwiki#vars#get_global('use_mouse')
nmap <buffer> <S-LeftMouse> <NOP> nmap <buffer> <S-LeftMouse> <NOP>
nmap <buffer> <C-LeftMouse> <NOP> nmap <buffer> <C-LeftMouse> <NOP>
nnoremap <silent><buffer> <2-LeftMouse> :call vimwiki#base#follow_link('nosplit', 0, 1, "\<lt>2-LeftMouse>")<CR> nnoremap <silent><buffer> <2-LeftMouse>
\ :call vimwiki#base#follow_link('nosplit', 0, 1, "\<lt>2-LeftMouse>")<CR>
nnoremap <silent><buffer> <S-2-LeftMouse> <LeftMouse>:VimwikiSplitLink<CR> nnoremap <silent><buffer> <S-2-LeftMouse> <LeftMouse>:VimwikiSplitLink<CR>
nnoremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitLink<CR> nnoremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitLink<CR>
nnoremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackLink<CR> nnoremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackLink<CR>
@ -337,46 +341,39 @@ endif
if !hasmapto('<Plug>Vimwiki2HTML') if !hasmapto('<Plug>Vimwiki2HTML')
exe 'nmap <buffer> '.g:vimwiki_map_prefix.'h <Plug>Vimwiki2HTML' exe 'nmap <buffer> '.vimwiki#vars#get_global('map_prefix').'h <Plug>Vimwiki2HTML'
endif endif
nnoremap <script><buffer> nnoremap <script><buffer> <Plug>Vimwiki2HTML :Vimwiki2HTML<CR>
\ <Plug>Vimwiki2HTML :Vimwiki2HTML<CR>
if !hasmapto('<Plug>Vimwiki2HTMLBrowse') if !hasmapto('<Plug>Vimwiki2HTMLBrowse')
exe 'nmap <buffer> '.g:vimwiki_map_prefix.'hh <Plug>Vimwiki2HTMLBrowse' exe 'nmap <buffer> '.vimwiki#vars#get_global('map_prefix').'hh <Plug>Vimwiki2HTMLBrowse'
endif endif
nnoremap <script><buffer> nnoremap <script><buffer> <Plug>Vimwiki2HTMLBrowse :Vimwiki2HTMLBrowse<CR>
\ <Plug>Vimwiki2HTMLBrowse :Vimwiki2HTMLBrowse<CR>
if !hasmapto('<Plug>VimwikiFollowLink') if !hasmapto('<Plug>VimwikiFollowLink')
nmap <silent><buffer> <CR> <Plug>VimwikiFollowLink nmap <silent><buffer> <CR> <Plug>VimwikiFollowLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiFollowLink :VimwikiFollowLink<CR>
\ <Plug>VimwikiFollowLink :VimwikiFollowLink<CR>
if !hasmapto('<Plug>VimwikiSplitLink') if !hasmapto('<Plug>VimwikiSplitLink')
nmap <silent><buffer> <S-CR> <Plug>VimwikiSplitLink nmap <silent><buffer> <S-CR> <Plug>VimwikiSplitLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiSplitLink :VimwikiSplitLink<CR>
\ <Plug>VimwikiSplitLink :VimwikiSplitLink<CR>
if !hasmapto('<Plug>VimwikiVSplitLink') if !hasmapto('<Plug>VimwikiVSplitLink')
nmap <silent><buffer> <C-CR> <Plug>VimwikiVSplitLink nmap <silent><buffer> <C-CR> <Plug>VimwikiVSplitLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiVSplitLink :VimwikiVSplitLink<CR>
\ <Plug>VimwikiVSplitLink :VimwikiVSplitLink<CR>
if !hasmapto('<Plug>VimwikiNormalizeLink') if !hasmapto('<Plug>VimwikiNormalizeLink')
nmap <silent><buffer> + <Plug>VimwikiNormalizeLink nmap <silent><buffer> + <Plug>VimwikiNormalizeLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiNormalizeLink :VimwikiNormalizeLink 0<CR>
\ <Plug>VimwikiNormalizeLink :VimwikiNormalizeLink 0<CR>
if !hasmapto('<Plug>VimwikiNormalizeLinkVisual') if !hasmapto('<Plug>VimwikiNormalizeLinkVisual')
vmap <silent><buffer> + <Plug>VimwikiNormalizeLinkVisual vmap <silent><buffer> + <Plug>VimwikiNormalizeLinkVisual
endif endif
vnoremap <silent><script><buffer> vnoremap <silent><script><buffer> <Plug>VimwikiNormalizeLinkVisual :<C-U>VimwikiNormalizeLink 1<CR>
\ <Plug>VimwikiNormalizeLinkVisual :<C-U>VimwikiNormalizeLink 1<CR>
if !hasmapto('<Plug>VimwikiNormalizeLinkVisualCR') if !hasmapto('<Plug>VimwikiNormalizeLinkVisualCR')
vmap <silent><buffer> <CR> <Plug>VimwikiNormalizeLinkVisualCR vmap <silent><buffer> <CR> <Plug>VimwikiNormalizeLinkVisualCR
@ -388,50 +385,42 @@ if !hasmapto('<Plug>VimwikiTabnewLink')
nmap <silent><buffer> <D-CR> <Plug>VimwikiTabnewLink nmap <silent><buffer> <D-CR> <Plug>VimwikiTabnewLink
nmap <silent><buffer> <C-S-CR> <Plug>VimwikiTabnewLink nmap <silent><buffer> <C-S-CR> <Plug>VimwikiTabnewLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiTabnewLink :VimwikiTabnewLink<CR>
\ <Plug>VimwikiTabnewLink :VimwikiTabnewLink<CR>
if !hasmapto('<Plug>VimwikiGoBackLink') if !hasmapto('<Plug>VimwikiGoBackLink')
nmap <silent><buffer> <BS> <Plug>VimwikiGoBackLink nmap <silent><buffer> <BS> <Plug>VimwikiGoBackLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiGoBackLink :VimwikiGoBackLink<CR>
\ <Plug>VimwikiGoBackLink :VimwikiGoBackLink<CR>
if !hasmapto('<Plug>VimwikiNextLink') if !hasmapto('<Plug>VimwikiNextLink')
nmap <silent><buffer> <TAB> <Plug>VimwikiNextLink nmap <silent><buffer> <TAB> <Plug>VimwikiNextLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiNextLink :VimwikiNextLink<CR>
\ <Plug>VimwikiNextLink :VimwikiNextLink<CR>
if !hasmapto('<Plug>VimwikiPrevLink') if !hasmapto('<Plug>VimwikiPrevLink')
nmap <silent><buffer> <S-TAB> <Plug>VimwikiPrevLink nmap <silent><buffer> <S-TAB> <Plug>VimwikiPrevLink
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiPrevLink :VimwikiPrevLink<CR>
\ <Plug>VimwikiPrevLink :VimwikiPrevLink<CR>
if !hasmapto('<Plug>VimwikiDeleteLink') if !hasmapto('<Plug>VimwikiDeleteLink')
exe 'nmap <silent><buffer> '.g:vimwiki_map_prefix.'d <Plug>VimwikiDeleteLink' exe 'nmap <silent><buffer> '.vimwiki#vars#get_global('map_prefix').'d <Plug>VimwikiDeleteLink'
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiDeleteLink :VimwikiDeleteLink<CR>
\ <Plug>VimwikiDeleteLink :VimwikiDeleteLink<CR>
if !hasmapto('<Plug>VimwikiRenameLink') if !hasmapto('<Plug>VimwikiRenameLink')
exe 'nmap <silent><buffer> '.g:vimwiki_map_prefix.'r <Plug>VimwikiRenameLink' exe 'nmap <silent><buffer> '.vimwiki#vars#get_global('map_prefix').'r <Plug>VimwikiRenameLink'
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiRenameLink :VimwikiRenameLink<CR>
\ <Plug>VimwikiRenameLink :VimwikiRenameLink<CR>
if !hasmapto('<Plug>VimwikiDiaryNextDay') if !hasmapto('<Plug>VimwikiDiaryNextDay')
nmap <silent><buffer> <C-Down> <Plug>VimwikiDiaryNextDay nmap <silent><buffer> <C-Down> <Plug>VimwikiDiaryNextDay
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiDiaryNextDay :VimwikiDiaryNextDay<CR>
\ <Plug>VimwikiDiaryNextDay :VimwikiDiaryNextDay<CR>
if !hasmapto('<Plug>VimwikiDiaryPrevDay') if !hasmapto('<Plug>VimwikiDiaryPrevDay')
nmap <silent><buffer> <C-Up> <Plug>VimwikiDiaryPrevDay nmap <silent><buffer> <C-Up> <Plug>VimwikiDiaryPrevDay
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiDiaryPrevDay :VimwikiDiaryPrevDay<CR>
\ <Plug>VimwikiDiaryPrevDay :VimwikiDiaryPrevDay<CR>
" List mappings " List mappings
if !hasmapto('<Plug>VimwikiToggleListItem') if !hasmapto('<Plug>VimwikiToggleListItem')
@ -442,10 +431,16 @@ if !hasmapto('<Plug>VimwikiToggleListItem')
vmap <silent><buffer> <C-@> <Plug>VimwikiToggleListItem vmap <silent><buffer> <C-@> <Plug>VimwikiToggleListItem
endif endif
endif endif
if !hasmapto('<Plug>VimwikiToggleRejectedListItem')
nmap <silent><buffer> glx <Plug>VimwikiToggleRejectedListItem
vmap <silent><buffer> glx <Plug>VimwikiToggleRejectedListItem
endif
nnoremap <silent><script><buffer> <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR>
vnoremap <silent><script><buffer> <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR>
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer>
\ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR> \ <Plug>VimwikiToggleRejectedListItem :VimwikiToggleRejectedListItem<CR>
vnoremap <silent><script><buffer> vnoremap <silent><script><buffer>
\ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR> \ <Plug>VimwikiToggleRejectedListItem :VimwikiToggleRejectedListItem<CR>
if !hasmapto('<Plug>VimwikiIncrementListItem') if !hasmapto('<Plug>VimwikiIncrementListItem')
nmap <silent><buffer> gln <Plug>VimwikiIncrementListItem nmap <silent><buffer> gln <Plug>VimwikiIncrementListItem
@ -455,39 +450,31 @@ if !hasmapto('<Plug>VimwikiDecrementListItem')
nmap <silent><buffer> glp <Plug>VimwikiDecrementListItem nmap <silent><buffer> glp <Plug>VimwikiDecrementListItem
vmap <silent><buffer> glp <Plug>VimwikiDecrementListItem vmap <silent><buffer> glp <Plug>VimwikiDecrementListItem
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR>
\ <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR> vnoremap <silent><script><buffer> <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR>
vnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR>
\ <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR> vnoremap <silent><script><buffer> <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR>
nnoremap <silent><script><buffer>
\ <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR>
vnoremap <silent><script><buffer>
\ <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR>
if !hasmapto('<Plug>VimwikiDecreaseLvlSingleItem', 'i') if !hasmapto('<Plug>VimwikiDecreaseLvlSingleItem', 'i')
imap <silent><buffer> <C-D> imap <silent><buffer> <C-D> <Plug>VimwikiDecreaseLvlSingleItem
\ <Plug>VimwikiDecreaseLvlSingleItem
endif endif
inoremap <silent><script><buffer> <Plug>VimwikiDecreaseLvlSingleItem inoremap <silent><script><buffer> <Plug>VimwikiDecreaseLvlSingleItem
\ <C-O>:VimwikiListChangeLvl decrease 0<CR> \ <C-O>:VimwikiListChangeLvl decrease 0<CR>
if !hasmapto('<Plug>VimwikiIncreaseLvlSingleItem', 'i') if !hasmapto('<Plug>VimwikiIncreaseLvlSingleItem', 'i')
imap <silent><buffer> <C-T> imap <silent><buffer> <C-T> <Plug>VimwikiIncreaseLvlSingleItem
\ <Plug>VimwikiIncreaseLvlSingleItem
endif endif
inoremap <silent><script><buffer> <Plug>VimwikiIncreaseLvlSingleItem inoremap <silent><script><buffer> <Plug>VimwikiIncreaseLvlSingleItem
\ <C-O>:VimwikiListChangeLvl increase 0<CR> \ <C-O>:VimwikiListChangeLvl increase 0<CR>
if !hasmapto('<Plug>VimwikiListNextSymbol', 'i') if !hasmapto('<Plug>VimwikiListNextSymbol', 'i')
imap <silent><buffer> <C-L><C-J> imap <silent><buffer> <C-L><C-J> <Plug>VimwikiListNextSymbol
\ <Plug>VimwikiListNextSymbol
endif endif
inoremap <silent><script><buffer> <Plug>VimwikiListNextSymbol inoremap <silent><script><buffer> <Plug>VimwikiListNextSymbol
\ <C-O>:VimwikiListChangeSymbolI next<CR> \ <C-O>:VimwikiListChangeSymbolI next<CR>
if !hasmapto('<Plug>VimwikiListPrevSymbol', 'i') if !hasmapto('<Plug>VimwikiListPrevSymbol', 'i')
imap <silent><buffer> <C-L><C-K> imap <silent><buffer> <C-L><C-K> <Plug>VimwikiListPrevSymbol
\ <Plug>VimwikiListPrevSymbol
endif endif
inoremap <silent><script><buffer> <Plug>VimwikiListPrevSymbol inoremap <silent><script><buffer> <Plug>VimwikiListPrevSymbol
\ <C-O>:VimwikiListChangeSymbolI prev<CR> \ <C-O>:VimwikiListChangeSymbolI prev<CR>
@ -503,15 +490,13 @@ nnoremap <silent> <buffer> O :<C-U>call vimwiki#lst#kbd_O()<CR>
if !hasmapto('<Plug>VimwikiRenumberList') if !hasmapto('<Plug>VimwikiRenumberList')
nmap <silent><buffer> glr <Plug>VimwikiRenumberList nmap <silent><buffer> glr <Plug>VimwikiRenumberList
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiRenumberList :VimwikiRenumberList<CR>
\ <Plug>VimwikiRenumberList :VimwikiRenumberList<CR>
if !hasmapto('<Plug>VimwikiRenumberAllLists') if !hasmapto('<Plug>VimwikiRenumberAllLists')
nmap <silent><buffer> gLr <Plug>VimwikiRenumberAllLists nmap <silent><buffer> gLr <Plug>VimwikiRenumberAllLists
nmap <silent><buffer> gLR <Plug>VimwikiRenumberAllLists nmap <silent><buffer> gLR <Plug>VimwikiRenumberAllLists
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiRenumberAllLists :VimwikiRenumberAllLists<CR>
\ <Plug>VimwikiRenumberAllLists :VimwikiRenumberAllLists<CR>
if !hasmapto('<Plug>VimwikiDecreaseLvlSingleItem') if !hasmapto('<Plug>VimwikiDecreaseLvlSingleItem')
map <silent><buffer> glh <Plug>VimwikiDecreaseLvlSingleItem map <silent><buffer> glh <Plug>VimwikiDecreaseLvlSingleItem
@ -542,16 +527,14 @@ noremap <silent><script><buffer>
if !hasmapto('<Plug>VimwikiRemoveSingleCB') if !hasmapto('<Plug>VimwikiRemoveSingleCB')
map <silent><buffer> gl<Space> <Plug>VimwikiRemoveSingleCB map <silent><buffer> gl<Space> <Plug>VimwikiRemoveSingleCB
endif endif
noremap <silent><script><buffer> noremap <silent><script><buffer> <Plug>VimwikiRemoveSingleCB :VimwikiRemoveSingleCB<CR>
\ <Plug>VimwikiRemoveSingleCB :VimwikiRemoveSingleCB<CR>
if !hasmapto('<Plug>VimwikiRemoveCBInList') if !hasmapto('<Plug>VimwikiRemoveCBInList')
map <silent><buffer> gL<Space> <Plug>VimwikiRemoveCBInList map <silent><buffer> gL<Space> <Plug>VimwikiRemoveCBInList
endif endif
noremap <silent><script><buffer> noremap <silent><script><buffer> <Plug>VimwikiRemoveCBInList :VimwikiRemoveCBInList<CR>
\ <Plug>VimwikiRemoveCBInList :VimwikiRemoveCBInList<CR>
for s:char in keys(g:vimwiki_bullet_types) for s:char in vimwiki#vars#get_syntaxlocal('bullet_types')
if !hasmapto(':VimwikiChangeSymbolTo '.s:char.'<CR>') if !hasmapto(':VimwikiChangeSymbolTo '.s:char.'<CR>')
exe 'noremap <silent><buffer> gl'.s:char.' :VimwikiChangeSymbolTo '.s:char.'<CR>' exe 'noremap <silent><buffer> gl'.s:char.' :VimwikiChangeSymbolTo '.s:char.'<CR>'
endif endif
@ -560,7 +543,7 @@ for s:char in keys(g:vimwiki_bullet_types)
endif endif
endfor endfor
for s:typ in g:vimwiki_number_types for s:typ in vimwiki#vars#get_syntaxlocal('number_types')
if !hasmapto(':VimwikiChangeSymbolTo '.s:typ.'<CR>') if !hasmapto(':VimwikiChangeSymbolTo '.s:typ.'<CR>')
exe 'noremap <silent><buffer> gl'.s:typ[0].' :VimwikiChangeSymbolTo '.s:typ.'<CR>' exe 'noremap <silent><buffer> gl'.s:typ[0].' :VimwikiChangeSymbolTo '.s:typ.'<CR>'
endif endif
@ -570,9 +553,8 @@ for s:typ in g:vimwiki_number_types
endfor endfor
function! s:CR(normal, just_mrkr)
function! s:CR(normal, just_mrkr) "{{{ if vimwiki#vars#get_global('table_mappings')
if g:vimwiki_table_mappings
let res = vimwiki#tbl#kbd_cr() let res = vimwiki#tbl#kbd_cr()
if res != "" if res != ""
exe "normal! " . res . "\<Right>" exe "normal! " . res . "\<Right>"
@ -581,7 +563,7 @@ function! s:CR(normal, just_mrkr) "{{{
endif endif
endif endif
call vimwiki#lst#kbd_cr(a:normal, a:just_mrkr) call vimwiki#lst#kbd_cr(a:normal, a:just_mrkr)
endfunction "}}} endfunction
if !hasmapto('VimwikiReturn', 'i') if !hasmapto('VimwikiReturn', 'i')
if maparg('<CR>', 'i') !~? '<Esc>:VimwikiReturn' if maparg('<CR>', 'i') !~? '<Esc>:VimwikiReturn'
@ -593,7 +575,7 @@ if !hasmapto('VimwikiReturn', 'i')
endif endif
"Table mappings "Table mappings
if g:vimwiki_table_mappings if vimwiki#vars#get_global('table_mappings')
inoremap <expr> <buffer> <Tab> vimwiki#tbl#kbd_tab() inoremap <expr> <buffer> <Tab> vimwiki#tbl#kbd_tab()
inoremap <expr> <buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab() inoremap <expr> <buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab()
endif endif
@ -605,8 +587,7 @@ nnoremap <buffer> gww :VimwikiTableAlignW<CR>
if !hasmapto('<Plug>VimwikiTableMoveColumnLeft') if !hasmapto('<Plug>VimwikiTableMoveColumnLeft')
nmap <silent><buffer> <A-Left> <Plug>VimwikiTableMoveColumnLeft nmap <silent><buffer> <A-Left> <Plug>VimwikiTableMoveColumnLeft
endif endif
nnoremap <silent><script><buffer> nnoremap <silent><script><buffer> <Plug>VimwikiTableMoveColumnLeft :VimwikiTableMoveColumnLeft<CR>
\ <Plug>VimwikiTableMoveColumnLeft :VimwikiTableMoveColumnLeft<CR>
if !hasmapto('<Plug>VimwikiTableMoveColumnRight') if !hasmapto('<Plug>VimwikiTableMoveColumnRight')
nmap <silent><buffer> <A-Right> <Plug>VimwikiTableMoveColumnRight nmap <silent><buffer> <A-Right> <Plug>VimwikiTableMoveColumnRight
endif endif
@ -615,12 +596,21 @@ nnoremap <silent><script><buffer>
" Text objects {{{ " ------------------------------------------------
onoremap <silent><buffer> ah :<C-U>call vimwiki#base#TO_header(0, 0)<CR> " Text objects
vnoremap <silent><buffer> ah :<C-U>call vimwiki#base#TO_header(0, 1)<CR> " ------------------------------------------------
onoremap <silent><buffer> ih :<C-U>call vimwiki#base#TO_header(1, 0)<CR> onoremap <silent><buffer> ah :<C-U>call vimwiki#base#TO_header(0, 0, v:count1)<CR>
vnoremap <silent><buffer> ih :<C-U>call vimwiki#base#TO_header(1, 1)<CR> vnoremap <silent><buffer> ah :<C-U>call vimwiki#base#TO_header(0, 0, v:count1)<CR>
onoremap <silent><buffer> ih :<C-U>call vimwiki#base#TO_header(1, 0, v:count1)<CR>
vnoremap <silent><buffer> ih :<C-U>call vimwiki#base#TO_header(1, 0, v:count1)<CR>
onoremap <silent><buffer> aH :<C-U>call vimwiki#base#TO_header(0, 1, v:count1)<CR>
vnoremap <silent><buffer> aH :<C-U>call vimwiki#base#TO_header(0, 1, v:count1)<CR>
onoremap <silent><buffer> iH :<C-U>call vimwiki#base#TO_header(1, 1, v:count1)<CR>
vnoremap <silent><buffer> iH :<C-U>call vimwiki#base#TO_header(1, 1, v:count1)<CR>
onoremap <silent><buffer> a\ :<C-U>call vimwiki#base#TO_table_cell(0, 0)<CR> onoremap <silent><buffer> a\ :<C-U>call vimwiki#base#TO_table_cell(0, 0)<CR>
vnoremap <silent><buffer> a\ :<C-U>call vimwiki#base#TO_table_cell(0, 1)<CR> vnoremap <silent><buffer> a\ :<C-U>call vimwiki#base#TO_table_cell(0, 1)<CR>
@ -643,8 +633,7 @@ vnoremap <silent><buffer> il :<C-U>call vimwiki#lst#TO_list_item(1, 1)<CR>
if !hasmapto('<Plug>VimwikiAddHeaderLevel') if !hasmapto('<Plug>VimwikiAddHeaderLevel')
nmap <silent><buffer> = <Plug>VimwikiAddHeaderLevel nmap <silent><buffer> = <Plug>VimwikiAddHeaderLevel
endif endif
nnoremap <silent><buffer> <Plug>VimwikiAddHeaderLevel : nnoremap <silent><buffer> <Plug>VimwikiAddHeaderLevel :<C-U>call vimwiki#base#AddHeaderLevel()<CR>
\<C-U>call vimwiki#base#AddHeaderLevel()<CR>
if !hasmapto('<Plug>VimwikiRemoveHeaderLevel') if !hasmapto('<Plug>VimwikiRemoveHeaderLevel')
nmap <silent><buffer> - <Plug>VimwikiRemoveHeaderLevel nmap <silent><buffer> - <Plug>VimwikiRemoveHeaderLevel
@ -652,43 +641,59 @@ endif
nnoremap <silent><buffer> <Plug>VimwikiRemoveHeaderLevel : nnoremap <silent><buffer> <Plug>VimwikiRemoveHeaderLevel :
\<C-U>call vimwiki#base#RemoveHeaderLevel()<CR> \<C-U>call vimwiki#base#RemoveHeaderLevel()<CR>
if !hasmapto('<Plug>VimwikiGoToParentHeader')
nmap <silent><buffer> ]u <Plug>VimwikiGoToParentHeader
nmap <silent><buffer> [u <Plug>VimwikiGoToParentHeader
endif
nnoremap <silent><buffer> <Plug>VimwikiGoToParentHeader :
\<C-u>call vimwiki#base#goto_parent_header()<CR>
" }}} if !hasmapto('<Plug>VimwikiGoToNextHeader')
nmap <silent><buffer> ]] <Plug>VimwikiGoToNextHeader
endif
nnoremap <silent><buffer> <Plug>VimwikiGoToNextHeader :
\<C-u>call vimwiki#base#goto_next_header()<CR>
" KEYBINDINGS }}} if !hasmapto('<Plug>VimwikiGoToPrevHeader')
nmap <silent><buffer> [[ <Plug>VimwikiGoToPrevHeader
endif
nnoremap <silent><buffer> <Plug>VimwikiGoToPrevHeader :
\<C-u>call vimwiki#base#goto_prev_header()<CR>
" AUTOCOMMANDS {{{ if !hasmapto('<Plug>VimwikiGoToNextSiblingHeader')
if VimwikiGet('auto_export') nmap <silent><buffer> ]= <Plug>VimwikiGoToNextSiblingHeader
endif
nnoremap <silent><buffer> <Plug>VimwikiGoToNextSiblingHeader :
\<C-u>call vimwiki#base#goto_sibling(+1)<CR>
if !hasmapto('<Plug>VimwikiGoToPrevSiblingHeader')
nmap <silent><buffer> [= <Plug>VimwikiGoToPrevSiblingHeader
endif
nnoremap <silent><buffer> <Plug>VimwikiGoToPrevSiblingHeader :
\<C-u>call vimwiki#base#goto_sibling(-1)<CR>
if vimwiki#vars#get_wikilocal('auto_export')
" Automatically generate HTML on page write. " Automatically generate HTML on page write.
augroup vimwiki augroup vimwiki
au BufWritePost <buffer> au BufWritePost <buffer>
\ call vimwiki#html#Wiki2HTML(expand(VimwikiGet('path_html')), \ call vimwiki#html#Wiki2HTML(expand(vimwiki#vars#get_wikilocal('path_html')),
\ expand('%')) \ expand('%'))
augroup END augroup END
endif endif
if VimwikiGet('auto_toc') if vimwiki#vars#get_wikilocal('auto_toc')
" Automatically update the TOC *before* the file is written " Automatically update the TOC *before* the file is written
augroup vimwiki augroup vimwiki
au BufWritePre <buffer> call vimwiki#base#table_of_contents(0) au BufWritePre <buffer> call vimwiki#base#table_of_contents(0)
augroup END augroup END
endif endif
if VimwikiGet('auto_tags') if vimwiki#vars#get_wikilocal('auto_tags')
" Automatically update tags metadata on page write. " Automatically update tags metadata on page write.
augroup vimwiki augroup vimwiki
au BufWritePost <buffer> call vimwiki#tags#update_tags(0, '') au BufWritePost <buffer> call vimwiki#tags#update_tags(0, '')
augroup END augroup END
endif endif
" AUTOCOMMANDS }}}
" PASTE, CAT URL {{{
" html commands
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p'))
" }}}
" DEBUGGING {{{
command! VimwikiPrintWikiState call vimwiki#base#print_wiki_state()
command! VimwikiReadLocalOptions call vimwiki#base#read_wiki_options(1)
" }}}

View File

@ -1,462 +1,263 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki plugin file " Vimwiki plugin file
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki " GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki
if exists("g:loaded_vimwiki") || &cp if exists("g:loaded_vimwiki") || &cp
finish finish
endif endif
let g:loaded_vimwiki = 1 let g:loaded_vimwiki = 1
let s:old_cpo = &cpo let s:old_cpo = &cpo
set cpo&vim set cpo&vim
" HELPER functions {{{ if exists('g:vimwiki_autowriteall')
function! s:default(varname, value) "{{{ let s:vimwiki_autowriteall_saved = g:vimwiki_autowriteall
if !exists('g:vimwiki_'.a:varname) else
let g:vimwiki_{a:varname} = a:value let s:vimwiki_autowriteall_saved = 1
endif endif
endfunction "}}}
function! s:path_html(idx) "{{{
let path_html = VimwikiGet('path_html', a:idx)
if !empty(path_html)
return path_html
else
let path = VimwikiGet('path', a:idx)
return substitute(path, '[/\\]\+$', '', '').'_html/'
endif
endfunction "}}}
function! s:normalize_path(path) "{{{ " this is called when the cursor leaves the buffer
" resolve doesn't work quite right with symlinks ended with / or \ function! s:setup_buffer_leave()
let path = substitute(a:path, '[/\\]\+$', '', '') " don't do anything if it's not managed by Vimwiki (that is, when it's not in
if path !~# '^scp:' " a registered wiki and not a temporary wiki)
return resolve(expand(path)).'/' if vimwiki#vars#get_bufferlocal('wiki_nr') == -1
else
return path.'/'
endif
endfunction "}}}
function! Validate_wiki_options(idx) " {{{
call VimwikiSet('path', s:normalize_path(VimwikiGet('path', a:idx)), a:idx)
call VimwikiSet('path_html', s:normalize_path(s:path_html(a:idx)), a:idx)
call VimwikiSet('template_path',
\ s:normalize_path(VimwikiGet('template_path', a:idx)), a:idx)
call VimwikiSet('diary_rel_path',
\ s:normalize_path(VimwikiGet('diary_rel_path', a:idx)), a:idx)
endfunction " }}}
function! s:vimwiki_idx() " {{{
if exists('b:vimwiki_idx')
return b:vimwiki_idx
else
return -1
endif
endfunction " }}}
function! s:setup_buffer_leave() "{{{
if &filetype ==? 'vimwiki'
" cache global vars of current state XXX: SLOW!?
call vimwiki#base#cache_buffer_state()
endif
let &autowriteall = s:vimwiki_autowriteall
" Set up menu
if g:vimwiki_menu != ""
exe 'nmenu disable '.g:vimwiki_menu.'.Table'
endif
endfunction "}}}
function! s:setup_filetype() "{{{
" Find what wiki current buffer belongs to.
let path = expand('%:p:h')
let idx = vimwiki#base#find_wiki(path)
if idx == -1 && g:vimwiki_global_ext == 0
return return
endif endif
"XXX when idx = -1? (an orphan page has been detected)
"TODO: refactor (same code in setup_buffer_enter) let &autowriteall = s:vimwiki_autowriteall_saved
" The buffer's file is not in the path and user *does* want his wiki
" extension(s) to be global -- Add new wiki. if vimwiki#vars#get_global('menu') != ""
if idx == -1 exe 'nmenu disable '.vimwiki#vars#get_global('menu').'.Table'
let ext = '.'.expand('%:e')
" lookup syntax using g:vimwiki_ext2syntax
if has_key(g:vimwiki_ext2syntax, ext)
let syn = g:vimwiki_ext2syntax[ext]
else
let syn = s:vimwiki_defaults.syntax
endif
call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1})
let idx = len(g:vimwiki_list) - 1
call Validate_wiki_options(idx)
endif endif
" initialize and cache global vars of current state endfunction
call vimwiki#base#setup_buffer_state(idx)
unlet! b:vimwiki_fs_rescan
set filetype=vimwiki
endfunction "}}}
function! s:setup_buffer_enter() "{{{ " create a new temporary wiki for the current buffer
if !vimwiki#base#recall_buffer_state() function! s:create_temporary_wiki()
" Find what wiki current buffer belongs to. let path = expand('%:p:h')
" If wiki does not exist in g:vimwiki_list -- add new wiki there with let ext = '.'.expand('%:e')
" buffer's path and ext.
" Else set g:vimwiki_current_idx to that wiki index.
let path = expand('%:p:h')
let idx = vimwiki#base#find_wiki(path)
" The buffer's file is not in the path and user *does NOT* want his wiki let syntax_mapping = vimwiki#vars#get_global('ext2syntax')
" extension to be global -- Do not add new wiki. if has_key(syntax_mapping, ext)
if idx == -1 && g:vimwiki_global_ext == 0 let syntax = syntax_mapping[ext]
else
let syntax = vimwiki#vars#get_wikilocal_default('syntax')
endif
let new_temp_wiki_settings = {'path': path,
\ 'ext': ext,
\ 'syntax': syntax,
\ }
call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings)
" Update the wiki number of the current buffer, because it may have changed when adding this
" temporary wiki.
call vimwiki#vars#set_bufferlocal('wiki_nr', vimwiki#base#find_wiki(expand('%:p')))
endfunction
" This function is called when Vim opens a new buffer with a known wiki
" extension. Both when the buffer has never been opened in this session and
" when it has.
function! s:setup_new_wiki_buffer()
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
if wiki_nr == -1 " it's not in a known wiki directory
if vimwiki#vars#get_global('global_ext')
call s:create_temporary_wiki()
else
" the user does not want a temporary wiki, so do nothing
return return
endif endif
"TODO: refactor (same code in setup_filetype)
" The buffer's file is not in the path and user *does* want his wiki
" extension(s) to be global -- Add new wiki.
if idx == -1
let ext = '.'.expand('%:e')
" lookup syntax using g:vimwiki_ext2syntax
if has_key(g:vimwiki_ext2syntax, ext)
let syn = g:vimwiki_ext2syntax[ext]
else
let syn = s:vimwiki_defaults.syntax
endif
call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1})
let idx = len(g:vimwiki_list) - 1
call Validate_wiki_options(idx)
endif
" initialize and cache global vars of current state
call vimwiki#base#setup_buffer_state(idx)
endif endif
" If you have if vimwiki#vars#get_wikilocal('maxhi')
" au GUIEnter * VimwikiIndex call vimwiki#vars#set_bufferlocal('existing_wikifiles', vimwiki#base#get_wikilinks(wiki_nr, 1))
" Then change it to call vimwiki#vars#set_bufferlocal('existing_wikidirs',
" au GUIEnter * nested VimwikiIndex \ vimwiki#base#get_wiki_directories(wiki_nr))
if &filetype == ''
set filetype=vimwiki
elseif &syntax ==? 'vimwiki'
" to force a rescan of the filesystem which may have changed
" and update VimwikiLinks syntax group that depends on it;
" b:vimwiki_fs_rescan indicates that setup_filetype() has not been run
if exists("b:vimwiki_fs_rescan") && VimwikiGet('maxhi')
set syntax=vimwiki
endif
let b:vimwiki_fs_rescan = 1
endif endif
" Settings foldmethod, foldexpr and foldtext are local to window. Thus in a " this makes that ftplugin/vimwiki.vim and afterwards syntax/vimwiki.vim are
" new tab with the same buffer folding is reset to vim defaults. So we " sourced
" insist vimwiki folding here. setfiletype vimwiki
if g:vimwiki_folding ==? 'expr'
setlocal fdm=expr endfunction
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif g:vimwiki_folding ==? 'list' || g:vimwiki_folding ==? 'lists' " this is called when the cursor enters the buffer
setlocal fdm=expr function! s:setup_buffer_enter()
setlocal foldexpr=VimwikiFoldListLevel(v:lnum) " don't do anything if it's not managed by Vimwiki (that is, when it's not in
setlocal foldtext=VimwikiFoldText() " a registered wiki and not a temporary wiki)
elseif g:vimwiki_folding ==? 'syntax' if vimwiki#vars#get_bufferlocal('wiki_nr') == -1
setlocal fdm=syntax return
setlocal foldtext=VimwikiFoldText()
elseif g:vimwiki_folding ==? 'custom'
" do nothing
else
setlocal fdm=manual
normal! zE
endif endif
" And conceal level too. if &filetype != 'vimwiki'
if g:vimwiki_conceallevel && exists("+conceallevel") setfiletype vimwiki
let &conceallevel = g:vimwiki_conceallevel
endif endif
" Set up menu call s:set_global_options()
if g:vimwiki_menu != ""
exe 'nmenu enable '.g:vimwiki_menu.'.Table'
endif
endfunction "}}}
function! s:setup_buffer_reenter() "{{{ call s:set_windowlocal_options()
if !vimwiki#base#recall_buffer_state() endfunction
" Do not repeat work of s:setup_buffer_enter() and s:setup_filetype()
" Once should be enough ...
endif
if !exists("s:vimwiki_autowriteall")
let s:vimwiki_autowriteall = &autowriteall
endif
let &autowriteall = g:vimwiki_autowriteall
endfunction "}}}
function! s:setup_cleared_syntax() "{{{ highlight groups that get cleared
function! s:setup_cleared_syntax()
" highlight groups that get cleared
" on colorscheme change because they are not linked to Vim-predefined groups " on colorscheme change because they are not linked to Vim-predefined groups
hi def VimwikiBold term=bold cterm=bold gui=bold hi def VimwikiBold term=bold cterm=bold gui=bold
hi def VimwikiItalic term=italic cterm=italic gui=italic hi def VimwikiItalic term=italic cterm=italic gui=italic
hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic
hi def VimwikiUnderline gui=underline hi def VimwikiUnderline gui=underline
if g:vimwiki_hl_headers == 1 if vimwiki#vars#get_global('hl_headers') == 1
for i in range(1,6) for i in range(1,6)
execute 'hi def VimwikiHeader'.i.' guibg=bg guifg='.g:vimwiki_hcolor_guifg_{&bg}[i-1].' gui=bold ctermfg='.g:vimwiki_hcolor_ctermfg_{&bg}[i-1].' term=bold cterm=bold' execute 'hi def VimwikiHeader'.i.' guibg=bg guifg='
\ . vimwiki#vars#get_global('hcolor_guifg_'.&bg)[i-1]
\ .' gui=bold ctermfg='.vimwiki#vars#get_global('hcolor_ctermfg_'.&bg)[i-1]
\ .' term=bold cterm=bold'
endfor endfor
endif endif
endfunction "}}} endfunction
" OPTION get/set functions {{{
" return complete list of options
function! VimwikiGetOptionNames() "{{{
return keys(s:vimwiki_defaults)
endfunction "}}}
function! VimwikiGetOptions(...) "{{{ function! s:vimwiki_get_known_extensions()
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
let option_dict = {}
for kk in keys(s:vimwiki_defaults)
let option_dict[kk] = VimwikiGet(kk, idx)
endfor
return option_dict
endfunction "}}}
" Return value of option for current wiki or if second parameter exists for
" wiki with a given index.
" If the option is not found, it is assumed to have been previously cached in a
" buffer local dictionary, that acts as a cache.
" If the option is not found in the buffer local dictionary, an error is thrown
function! VimwikiGet(option, ...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
if has_key(g:vimwiki_list[idx], a:option)
let val = g:vimwiki_list[idx][a:option]
elseif has_key(s:vimwiki_defaults, a:option)
let val = s:vimwiki_defaults[a:option]
let g:vimwiki_list[idx][a:option] = val
else
let val = b:vimwiki_list[a:option]
endif
" XXX no call to vimwiki#base here or else the whole autoload/base gets loaded!
return val
endfunction "}}}
" Set option for current wiki or if third parameter exists for
" wiki with a given index.
" If the option is not found or recognized (i.e. does not exist in
" s:vimwiki_defaults), it is saved in a buffer local dictionary, that acts
" as a cache.
" If the option is not found in the buffer local dictionary, an error is thrown
function! VimwikiSet(option, value, ...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
if has_key(s:vimwiki_defaults, a:option) ||
\ has_key(g:vimwiki_list[idx], a:option)
let g:vimwiki_list[idx][a:option] = a:value
elseif exists('b:vimwiki_list')
let b:vimwiki_list[a:option] = a:value
else
let b:vimwiki_list = {}
let b:vimwiki_list[a:option] = a:value
endif
endfunction "}}}
" Clear option for current wiki or if second parameter exists for
" wiki with a given index.
" Currently, only works if option was previously saved in the buffer local
" dictionary, that acts as a cache.
function! VimwikiClear(option, ...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
if exists('b:vimwiki_list') && has_key(b:vimwiki_list, a:option)
call remove(b:vimwiki_list, a:option)
endif
endfunction "}}}
" }}}
function! s:vimwiki_get_known_extensions() " {{{
" Getting all extensions that different wikis could have " Getting all extensions that different wikis could have
let extensions = {} let extensions = {}
for wiki in g:vimwiki_list for idx in range(vimwiki#vars#number_of_wikis())
if has_key(wiki, 'ext') let ext = vimwiki#vars#get_wikilocal('ext', idx)
let extensions[wiki.ext] = 1 let extensions[ext] = 1
else
let extensions['.wiki'] = 1
endif
endfor endfor
" append map g:vimwiki_ext2syntax " append extensions from g:vimwiki_ext2syntax
for ext in keys(g:vimwiki_ext2syntax) for ext in keys(vimwiki#vars#get_global('ext2syntax'))
let extensions[ext] = 1 let extensions[ext] = 1
endfor endfor
return keys(extensions) return keys(extensions)
endfunction " }}} endfunction
" }}}
" CALLBACK functions "{{{ " Set settings which are global for Vim, but should only be executed for
" User can redefine it. " Vimwiki buffers. So they must be set when the cursor enters a Vimwiki buffer
if !exists("*VimwikiLinkHandler") "{{{ " and reset when the cursor leaves the buffer.
function! s:set_global_options()
let s:vimwiki_autowriteall_saved = &autowriteall
let &autowriteall = vimwiki#vars#get_global('autowriteall')
if vimwiki#vars#get_global('menu') !=# ''
exe 'nmenu enable '.vimwiki#vars#get_global('menu').'.Table'
endif
endfunction
" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
let foldmethod = vimwiki#vars#get_global('folding')
if foldmethod =~? '^expr.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^syntax.*'
setlocal foldmethod=syntax
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^custom.*'
" do nothing
else
setlocal foldmethod=manual
normal! zE
endif
if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &conceallevel = vimwiki#vars#get_global('conceallevel')
endif
if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
endfunction
" Initialization of Vimwiki starts here. Make sure everything below does not
" cause autoload/vimwiki/base.vim to be loaded
call vimwiki#vars#init()
" Define callback functions which the user can redefine
if !exists("*VimwikiLinkHandler")
function VimwikiLinkHandler(url) function VimwikiLinkHandler(url)
return 0 return 0
endfunction endfunction
endif "}}} endif
if !exists("*VimwikiLinkConverter") "{{{ if !exists("*VimwikiLinkConverter")
function VimwikiLinkConverter(url, source, target) function VimwikiLinkConverter(url, source, target)
" Return the empty string when unable to process link " Return the empty string when unable to process link
return '' return ''
endfunction endfunction
endif "}}} endif
if !exists("*VimwikiWikiIncludeHandler") "{{{ if !exists("*VimwikiWikiIncludeHandler")
function! VimwikiWikiIncludeHandler(value) "{{{ function! VimwikiWikiIncludeHandler(value)
return '' return ''
endfunction "}}} endfunction
endif "}}} endif
" CALLBACK }}}
" DEFAULT wiki {{{
let s:vimwiki_defaults = {}
let s:vimwiki_defaults.path = '~/vimwiki/'
let s:vimwiki_defaults.path_html = '' " '' is replaced by derived path.'_html/'
let s:vimwiki_defaults.css_name = 'style.css'
let s:vimwiki_defaults.index = 'index'
let s:vimwiki_defaults.ext = '.wiki'
let s:vimwiki_defaults.maxhi = 0
let s:vimwiki_defaults.syntax = 'default'
let s:vimwiki_defaults.template_path = '~/vimwiki/templates/'
let s:vimwiki_defaults.template_default = 'default'
let s:vimwiki_defaults.template_ext = '.tpl'
let s:vimwiki_defaults.nested_syntaxes = {} " Define autocommands for all known wiki extensions
let s:vimwiki_defaults.automatic_nested_syntaxes = 1
let s:vimwiki_defaults.auto_export = 0
let s:vimwiki_defaults.auto_toc = 0
" is wiki temporary -- was added to g:vimwiki_list by opening arbitrary wiki
" file.
let s:vimwiki_defaults.temp = 0
" diary let s:known_extensions = s:vimwiki_get_known_extensions()
let s:vimwiki_defaults.diary_rel_path = 'diary/'
let s:vimwiki_defaults.diary_index = 'diary'
let s:vimwiki_defaults.diary_header = 'Diary'
let s:vimwiki_defaults.diary_sort = 'desc'
" Do not change this! Will wait till vim become more datetime awareable. if index(s:known_extensions, '.wiki') > -1
let s:vimwiki_defaults.diary_link_fmt = '%Y-%m-%d' augroup filetypedetect
" clear FlexWiki's stuff
" NEW! in v2.0 au! * *.wiki
" custom_wiki2html augroup end
let s:vimwiki_defaults.custom_wiki2html = '' endif
"
let s:vimwiki_defaults.list_margin = -1
let s:vimwiki_defaults.auto_tags = 0
"}}}
" DEFAULT options {{{
call s:default('list', [s:vimwiki_defaults])
call s:default('use_mouse', 0)
call s:default('folding', '')
call s:default('menu', 'Vimwiki')
call s:default('global_ext', 1)
call s:default('ext2syntax', {}) " syntax map keyed on extension
call s:default('hl_headers', 0)
call s:default('hl_cb_checked', 0)
call s:default('list_ignore_newline', 1)
call s:default('text_ignore_newline', 1)
call s:default('listsyms', ' .oOX')
call s:default('use_calendar', 1)
call s:default('table_mappings', 1)
call s:default('table_auto_fmt', 1)
call s:default('w32_dir_enc', '')
call s:default('CJK_length', 0)
call s:default('dir_link', '')
call s:default('valid_html_tags', 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em')
call s:default('user_htmls', '')
call s:default('autowriteall', 1)
call s:default('toc_header', 'Contents')
call s:default('html_header_numbering', 0)
call s:default('html_header_numbering_sym', '')
call s:default('conceallevel', 2)
call s:default('url_maxsave', 15)
call s:default('diary_months',
\ {
\ 1: 'January', 2: 'February', 3: 'March',
\ 4: 'April', 5: 'May', 6: 'June',
\ 7: 'July', 8: 'August', 9: 'September',
\ 10: 'October', 11: 'November', 12: 'December'
\ })
call s:default('map_prefix', '<Leader>w')
call s:default('current_idx', 0)
call s:default('auto_chdir', 0)
" Scheme regexes should be defined even if syntax file is not loaded yet
" cause users should be able to <leader>w<leader>w without opening any
" vimwiki file first
" Scheme regexes {{{
call s:default('schemes', 'wiki\d\+,diary,local')
call s:default('web_schemes1', 'http,https,file,ftp,gopher,telnet,nntp,ldap,'.
\ 'rsync,imap,pop,irc,ircs,cvs,svn,svn+ssh,git,ssh,fish,sftp')
call s:default('web_schemes2', 'mailto,news,xmpp,sip,sips,doi,urn,tel,data')
let s:rxSchemes = '\%('.
\ join(split(g:vimwiki_schemes, '\s*,\s*'), '\|').'\|'.
\ join(split(g:vimwiki_web_schemes1, '\s*,\s*'), '\|').'\|'.
\ join(split(g:vimwiki_web_schemes2, '\s*,\s*'), '\|').
\ '\)'
call s:default('rxSchemeUrl', s:rxSchemes.':.*')
call s:default('rxSchemeUrlMatchScheme', '\zs'.s:rxSchemes.'\ze:.*')
call s:default('rxSchemeUrlMatchUrl', s:rxSchemes.':\zs.*\ze')
" scheme regexes }}}
for s:idx in range(len(g:vimwiki_list))
call Validate_wiki_options(s:idx)
endfor
"}}}
" AUTOCOMMANDS for all known wiki extensions {{{
augroup filetypedetect
" clear FlexWiki's stuff
au! * *.wiki
augroup end
augroup vimwiki augroup vimwiki
autocmd! autocmd!
for s:ext in s:vimwiki_get_known_extensions() for s:ext in s:known_extensions
exe 'autocmd BufEnter *'.s:ext.' call s:setup_buffer_reenter()' exe 'autocmd BufNewFile,BufRead *'.s:ext.' call s:setup_new_wiki_buffer()'
exe 'autocmd BufWinEnter *'.s:ext.' call s:setup_buffer_enter()' exe 'autocmd BufEnter *'.s:ext.' call s:setup_buffer_enter()'
exe 'autocmd BufLeave,BufHidden *'.s:ext.' call s:setup_buffer_leave()' exe 'autocmd BufLeave *'.s:ext.' call s:setup_buffer_leave()'
exe 'autocmd BufNewFile,BufRead, *'.s:ext.' call s:setup_filetype()'
exe 'autocmd ColorScheme *'.s:ext.' call s:setup_cleared_syntax()' exe 'autocmd ColorScheme *'.s:ext.' call s:setup_cleared_syntax()'
" Format tables when exit from insert mode. Do not use textwidth to " Format tables when exit from insert mode. Do not use textwidth to
" autowrap tables. " autowrap tables.
if g:vimwiki_table_auto_fmt if vimwiki#vars#get_global('table_auto_fmt')
exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))' exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))'
exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))' exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))'
endif endif
if vimwiki#vars#get_global('folding') =~? ':quick$'
" from http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode. Foldmethod is local to the window. Protect against
" screwing up folding when switching between windows.
exe 'autocmd InsertEnter *'.s:ext.' if !exists("w:last_fdm") | let w:last_fdm=&foldmethod'.
\ ' | setlocal foldmethod=manual | endif'
exe 'autocmd InsertLeave,WinLeave *'.s:ext.' if exists("w:last_fdm") |'.
\ 'let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif'
endif
endfor endfor
augroup END augroup END
"}}}
" COMMANDS {{{
command! VimwikiUISelect call vimwiki#base#ui_select() command! VimwikiUISelect call vimwiki#base#ui_select()
" XXX: why not using <count> instead of v:count1? " why not using <count> instead of v:count1?
" See Issue 324. " See https://github.com/vimwiki-backup/vimwiki/issues/324
command! -count=1 VimwikiIndex command! -count=1 VimwikiIndex
\ call vimwiki#base#goto_index(v:count1) \ call vimwiki#base#goto_index(v:count1)
command! -count=1 VimwikiTabIndex command! -count=1 VimwikiTabIndex
@ -465,73 +266,83 @@ command! -count=1 VimwikiTabIndex
command! -count=1 VimwikiDiaryIndex command! -count=1 VimwikiDiaryIndex
\ call vimwiki#diary#goto_diary_index(v:count1) \ call vimwiki#diary#goto_diary_index(v:count1)
command! -count=1 VimwikiMakeDiaryNote command! -count=1 VimwikiMakeDiaryNote
\ call vimwiki#diary#make_note(v:count1) \ call vimwiki#diary#make_note(v:count)
command! -count=1 VimwikiTabMakeDiaryNote command! -count=1 VimwikiTabMakeDiaryNote
\ call vimwiki#diary#make_note(v:count1, 1) \ call vimwiki#diary#make_note(v:count, 1)
command! -count=1 VimwikiMakeYesterdayDiaryNote command! -count=1 VimwikiMakeYesterdayDiaryNote
\ call vimwiki#diary#make_note(v:count1, 0, strftime(VimwikiGet('diary_link_fmt', v:count1 - 1), localtime() - 60*60*24)) \ call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() - 60*60*24))
command! -count=1 VimwikiMakeTomorrowDiaryNote
\ call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime() + 60*60*24))
command! VimwikiDiaryGenerateLinks command! VimwikiDiaryGenerateLinks
\ call vimwiki#diary#generate_diary_section() \ call vimwiki#diary#generate_diary_section()
"}}}
" MAPPINGS {{{
let s:map_prefix = vimwiki#vars#get_global('map_prefix')
if !hasmapto('<Plug>VimwikiIndex') if !hasmapto('<Plug>VimwikiIndex')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'w <Plug>VimwikiIndex' exe 'nmap <silent><unique> '.s:map_prefix.'w <Plug>VimwikiIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiIndex :VimwikiIndex<CR> nnoremap <unique><script> <Plug>VimwikiIndex :VimwikiIndex<CR>
if !hasmapto('<Plug>VimwikiTabIndex') if !hasmapto('<Plug>VimwikiTabIndex')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'t <Plug>VimwikiTabIndex' exe 'nmap <silent><unique> '.s:map_prefix.'t <Plug>VimwikiTabIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiTabIndex :VimwikiTabIndex<CR> nnoremap <unique><script> <Plug>VimwikiTabIndex :VimwikiTabIndex<CR>
if !hasmapto('<Plug>VimwikiUISelect') if !hasmapto('<Plug>VimwikiUISelect')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'s <Plug>VimwikiUISelect' exe 'nmap <silent><unique> '.s:map_prefix.'s <Plug>VimwikiUISelect'
endif endif
nnoremap <unique><script> <Plug>VimwikiUISelect :VimwikiUISelect<CR> nnoremap <unique><script> <Plug>VimwikiUISelect :VimwikiUISelect<CR>
if !hasmapto('<Plug>VimwikiDiaryIndex') if !hasmapto('<Plug>VimwikiDiaryIndex')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'i <Plug>VimwikiDiaryIndex' exe 'nmap <silent><unique> '.s:map_prefix.'i <Plug>VimwikiDiaryIndex'
endif endif
nnoremap <unique><script> <Plug>VimwikiDiaryIndex :VimwikiDiaryIndex<CR> nnoremap <unique><script> <Plug>VimwikiDiaryIndex :VimwikiDiaryIndex<CR>
if !hasmapto('<Plug>VimwikiDiaryGenerateLinks') if !hasmapto('<Plug>VimwikiDiaryGenerateLinks')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'<Leader>i <Plug>VimwikiDiaryGenerateLinks' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>i <Plug>VimwikiDiaryGenerateLinks'
endif endif
nnoremap <unique><script> <Plug>VimwikiDiaryGenerateLinks :VimwikiDiaryGenerateLinks<CR> nnoremap <unique><script> <Plug>VimwikiDiaryGenerateLinks :VimwikiDiaryGenerateLinks<CR>
if !hasmapto('<Plug>VimwikiMakeDiaryNote') if !hasmapto('<Plug>VimwikiMakeDiaryNote')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'<Leader>w <Plug>VimwikiMakeDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>w <Plug>VimwikiMakeDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiMakeDiaryNote :VimwikiMakeDiaryNote<CR> nnoremap <unique><script> <Plug>VimwikiMakeDiaryNote :VimwikiMakeDiaryNote<CR>
if !hasmapto('<Plug>VimwikiTabMakeDiaryNote') if !hasmapto('<Plug>VimwikiTabMakeDiaryNote')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'<Leader>t <Plug>VimwikiTabMakeDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>t <Plug>VimwikiTabMakeDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiTabMakeDiaryNote nnoremap <unique><script> <Plug>VimwikiTabMakeDiaryNote
\ :VimwikiTabMakeDiaryNote<CR> \ :VimwikiTabMakeDiaryNote<CR>
if !hasmapto('<Plug>VimwikiMakeYesterdayDiaryNote') if !hasmapto('<Plug>VimwikiMakeYesterdayDiaryNote')
exe 'nmap <silent><unique> '.g:vimwiki_map_prefix.'<Leader>y <Plug>VimwikiMakeYesterdayDiaryNote' exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>y <Plug>VimwikiMakeYesterdayDiaryNote'
endif endif
nnoremap <unique><script> <Plug>VimwikiMakeYesterdayDiaryNote nnoremap <unique><script> <Plug>VimwikiMakeYesterdayDiaryNote
\ :VimwikiMakeYesterdayDiaryNote<CR> \ :VimwikiMakeYesterdayDiaryNote<CR>
"}}} if !hasmapto('<Plug>VimwikiMakeTomorrowDiaryNote')
exe 'nmap <silent><unique> '.s:map_prefix.'<Leader>m <Plug>VimwikiMakeTomorrowDiaryNote'
endif
nnoremap <unique><script> <Plug>VimwikiMakeTomorrowDiaryNote
\ :VimwikiMakeTomorrowDiaryNote<CR>
" MENU {{{
function! s:build_menu(topmenu) function! s:build_menu(topmenu)
let idx = 0 for idx in range(vimwiki#vars#number_of_wikis())
while idx < len(g:vimwiki_list) let norm_path = fnamemodify(vimwiki#vars#get_wikilocal('path', idx), ':h:t')
let norm_path = fnamemodify(VimwikiGet('path', idx), ':h:t')
let norm_path = escape(norm_path, '\ \.') let norm_path = escape(norm_path, '\ \.')
execute 'menu '.a:topmenu.'.Open\ index.'.norm_path. execute 'menu '.a:topmenu.'.Open\ index.'.norm_path.
\ ' :call vimwiki#base#goto_index('.(idx + 1).')<CR>' \ ' :call vimwiki#base#goto_index('.(idx+1).')<CR>'
execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path. execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path.
\ ' :call vimwiki#diary#make_note('.(idx + 1).')<CR>' \ ' :call vimwiki#diary#make_note('.(idx+1).')<CR>'
let idx += 1 endfor
endwhile
endfunction endfunction
function! s:build_table_menu(topmenu) function! s:build_table_menu(topmenu)
@ -539,23 +350,23 @@ function! s:build_table_menu(topmenu)
exe 'menu '.a:topmenu.'.Table.Create\ (enter\ cols\ rows) :VimwikiTable ' exe 'menu '.a:topmenu.'.Table.Create\ (enter\ cols\ rows) :VimwikiTable '
exe 'nmenu '.a:topmenu.'.Table.Format<tab>gqq gqq' exe 'nmenu '.a:topmenu.'.Table.Format<tab>gqq gqq'
exe 'nmenu '.a:topmenu.'.Table.Move\ column\ left<tab><A-Left> :VimwikiTableMoveColumnLeft<CR>' exe 'nmenu '.a:topmenu.'.Table.Move\ column\ left<tab><A-Left> :VimwikiTableMoveColumnLeft<CR>'
exe 'nmenu '.a:topmenu.'.Table.Move\ column\ right<tab><A-Right> :VimwikiTableMoveColumnRight<CR>' exe 'nmenu '.a:topmenu.
\ '.Table.Move\ column\ right<tab><A-Right> :VimwikiTableMoveColumnRight<CR>'
exe 'nmenu disable '.a:topmenu.'.Table' exe 'nmenu disable '.a:topmenu.'.Table'
endfunction endfunction
"XXX make sure anything below does not cause autoload/base to be loaded
if !empty(g:vimwiki_menu)
call s:build_menu(g:vimwiki_menu)
call s:build_table_menu(g:vimwiki_menu)
endif
" }}}
" CALENDAR Hook "{{{ if !empty(vimwiki#vars#get_global('menu'))
if g:vimwiki_use_calendar call s:build_menu(vimwiki#vars#get_global('menu'))
call s:build_table_menu(vimwiki#vars#get_global('menu'))
endif
" Hook for calendar.vim
if vimwiki#vars#get_global('use_calendar')
let g:calendar_action = 'vimwiki#diary#calendar_action' let g:calendar_action = 'vimwiki#diary#calendar_action'
let g:calendar_sign = 'vimwiki#diary#calendar_sign' let g:calendar_sign = 'vimwiki#diary#calendar_sign'
endif endif
"}}}
let &cpo = s:old_cpo let &cpo = s:old_cpo

View File

@ -1,35 +0,0 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki syntax file
" Desc: Syntax definitions which are always available
" Home: https://github.com/vimwiki/vimwiki/
" Define Regexes of anchors for every syntax.
" This has to be separated from vimwiki_default.vim, vimwiki_markdown.vim, etc.
" because the latter are only loaded and available if the current wiki has the
" corresponding syntax
let g:vimwiki_default_header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let g:vimwiki_default_header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let g:vimwiki_default_bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_default_bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_default_wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let g:vimwiki_default_tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let g:vimwiki_default_tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:\([^:[:space:]]\+:\)*\(\s\|$\)'
let g:vimwiki_markdown_header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
let g:vimwiki_markdown_header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
let g:vimwiki_markdown_bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_markdown_bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_markdown_wikilink = g:vimwiki_default_wikilink "XXX plus markdown-style links
let g:vimwiki_markdown_tag_search = g:vimwiki_default_tag_search
let g:vimwiki_markdown_tag_match = g:vimwiki_default_tag_match
let g:vimwiki_media_header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let g:vimwiki_media_header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let g:vimwiki_media_bold_search = "'''\\zs[^']\\+\\ze'''"
let g:vimwiki_media_bold_match = '''''''__Text__'''''''
" ^- this strange looking thing is equivalent to "'''__Text__'''" but since we later
" want to call escape() on this string, we must keep it in single quotes
let g:vimwiki_media_wikilink = g:vimwiki_default_wikilink
let g:vimwiki_media_tag_search = g:vimwiki_default_tag_search " XXX rework to mediawiki categories format?
let g:vimwiki_media_tag_match = g:vimwiki_default_tag_match " XXX rework to mediawiki categories format?

View File

@ -1,398 +1,242 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file " Vimwiki syntax file
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" Quit if syntax file is already loaded " Quit if syntax file is already loaded
if version < 600 if v:version < 600
syntax clear syntax clear
elseif exists("b:current_syntax") elseif exists("b:current_syntax")
finish finish
endif endif
"TODO do nothing if ...? (?)
if VimwikiGet('maxhi')
let b:existing_wikifiles =
\ vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 1)
let b:existing_wikidirs =
\ vimwiki#base#get_wiki_directories(g:vimwiki_current_idx)
endif
"let b:xxx = 1
"TODO ? update wikilink syntax group here if really needed (?) for :e and such
"if VimwikiGet('maxhi')
" ...
"endif
" LINKS: assume this is common to all syntaxes "{{{ let s:current_syntax = vimwiki#vars#get_wikilocal('syntax')
" LINKS: WebLinks {{{
" match URL for common protocols;
" see http://en.wikipedia.org/wiki/URI_scheme http://tools.ietf.org/html/rfc3986
let g:vimwiki_rxWebProtocols = ''.
\ '\%('.
\ '\%('.
\ '\%('.join(split(g:vimwiki_web_schemes1, '\s*,\s*'), '\|').'\):'.
\ '\%(//\)'.
\ '\)'.
\ '\|'.
\ '\%('.join(split(g:vimwiki_web_schemes2, '\s*,\s*'), '\|').'\):'.
\ '\)'
"
let g:vimwiki_rxWeblinkUrl = g:vimwiki_rxWebProtocols .
\ '\S\{-1,}'. '\%(([^ \t()]*)\)\='
" }}}
" }}}
call vimwiki#u#reload_regexes()
" LINKS: setup of larger regexes {{{
" LINKS: setup wikilink regexps {{{
let s:wikilink_prefix = '[['
let s:wikilink_suffix = ']]'
let s:wikilink_separator = '|'
let s:rx_wikilink_prefix = vimwiki#u#escape(s:wikilink_prefix)
let s:rx_wikilink_suffix = vimwiki#u#escape(s:wikilink_suffix)
let s:rx_wikilink_separator = vimwiki#u#escape(s:wikilink_separator)
" templates for the creation of wiki links
" [[URL]]
let g:vimwiki_WikiLinkTemplate1 = s:wikilink_prefix . '__LinkUrl__'.
\ s:wikilink_suffix
" [[URL|DESCRIPTION]]
let g:vimwiki_WikiLinkTemplate2 = s:wikilink_prefix . '__LinkUrl__'.
\ s:wikilink_separator . '__LinkDescription__' . s:wikilink_suffix
" template for matching all wiki links with a given target file
let g:vimwiki_WikiLinkMatchUrlTemplate =
\ s:rx_wikilink_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ s:rx_wikilink_suffix .
\ '\|' .
\ s:rx_wikilink_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ s:rx_wikilink_separator .
\ '.*' .
\ s:rx_wikilink_suffix
let s:valid_chars = '[^\\\]]'
let g:vimwiki_rxWikiLinkUrl = s:valid_chars.'\{-}'
let g:vimwiki_rxWikiLinkDescr = s:valid_chars.'\{-}'
" this regexp defines what can form a link when the user presses <CR> in the
" buffer (and not on a link) to create a link
" basically, it's Ascii alphanumeric characters plus #|./@-_~ plus all
" non-Ascii characters
let g:vimwiki_rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]\+'
" [[URL]], or [[URL|DESCRIPTION]] call vimwiki#vars#populate_syntax_vars(s:current_syntax)
" a) match [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLink = s:rx_wikilink_prefix.
\ g:vimwiki_rxWikiLinkUrl.'\%('.s:rx_wikilink_separator.
\ g:vimwiki_rxWikiLinkDescr.'\)\?'.s:rx_wikilink_suffix
" b) match URL within [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLinkMatchUrl = s:rx_wikilink_prefix.
\ '\zs'. g:vimwiki_rxWikiLinkUrl.'\ze\%('. s:rx_wikilink_separator.
\ g:vimwiki_rxWikiLinkDescr.'\)\?'.s:rx_wikilink_suffix
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLinkMatchDescr = s:rx_wikilink_prefix.
\ g:vimwiki_rxWikiLinkUrl.s:rx_wikilink_separator.'\%('.
\ '\zs'. g:vimwiki_rxWikiLinkDescr. '\ze\)\?'. s:rx_wikilink_suffix
" }}}
" LINKS: Syntax helper {{{
let s:rx_wikilink_prefix1 = s:rx_wikilink_prefix . g:vimwiki_rxWikiLinkUrl .
\ s:rx_wikilink_separator
let s:rx_wikilink_suffix1 = s:rx_wikilink_suffix
" }}}
" LINKS: setup of wikiincl regexps {{{ " LINKS: highlighting is complicated due to "nonexistent" links feature
let g:vimwiki_rxWikiInclPrefix = '{{' function! s:add_target_syntax_ON(target, type)
let g:vimwiki_rxWikiInclSuffix = '}}'
let g:vimwiki_rxWikiInclSeparator = '|'
"
" '{{__LinkUrl__}}'
let g:vimwiki_WikiInclTemplate1 = g:vimwiki_rxWikiInclPrefix . '__LinkUrl__'.
\ g:vimwiki_rxWikiInclSuffix
" '{{__LinkUrl____LinkDescription__}}'
let g:vimwiki_WikiInclTemplate2 = g:vimwiki_rxWikiInclPrefix . '__LinkUrl__'.
\ '__LinkDescription__'.
\ g:vimwiki_rxWikiInclSuffix
let s:valid_chars = '[^\\\}]'
let g:vimwiki_rxWikiInclUrl = s:valid_chars.'\{-}'
let g:vimwiki_rxWikiInclArg = s:valid_chars.'\{-}'
let g:vimwiki_rxWikiInclArgs = '\%('. g:vimwiki_rxWikiInclSeparator. g:vimwiki_rxWikiInclArg. '\)'.'\{-}'
"
"
" *. {{URL}[{...}]} - i.e. {{URL}}, {{URL|ARG1}}, {{URL|ARG1|ARG2}}, etc.
" *a) match {{URL}[{...}]}
let g:vimwiki_rxWikiIncl = g:vimwiki_rxWikiInclPrefix.
\ g:vimwiki_rxWikiInclUrl.
\ g:vimwiki_rxWikiInclArgs. g:vimwiki_rxWikiInclSuffix
" *b) match URL within {{URL}[{...}]}
let g:vimwiki_rxWikiInclMatchUrl = g:vimwiki_rxWikiInclPrefix.
\ '\zs'. g:vimwiki_rxWikiInclUrl. '\ze'.
\ g:vimwiki_rxWikiInclArgs. g:vimwiki_rxWikiInclSuffix
" }}}
" LINKS: Syntax helper {{{
let g:vimwiki_rxWikiInclPrefix1 = g:vimwiki_rxWikiInclPrefix.
\ g:vimwiki_rxWikiInclUrl.g:vimwiki_rxWikiInclSeparator
let g:vimwiki_rxWikiInclSuffix1 = g:vimwiki_rxWikiInclArgs.
\ g:vimwiki_rxWikiInclSuffix
" }}}
" LINKS: Setup weblink regexps {{{
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
" Maxim:
" Simplify free-standing links: URL starts with non(letter|digit)scheme till
" the whitespace.
" Stuart, could you check it with markdown templated links? [](http://...), as
" the last bracket is the part of URL now?
let g:vimwiki_rxWeblink = '\<'. g:vimwiki_rxWeblinkUrl . '\S*'
" 0a) match URL within URL
let g:vimwiki_rxWeblinkMatchUrl = g:vimwiki_rxWeblink
" 0b) match DESCRIPTION within URL
let g:vimwiki_rxWeblinkMatchDescr = ''
" }}}
" LINKS: Setup anylink regexps {{{
let g:vimwiki_rxAnyLink = g:vimwiki_rxWikiLink.'\|'.
\ g:vimwiki_rxWikiIncl.'\|'.g:vimwiki_rxWeblink
" }}}
" }}} end of Links
" LINKS: highlighting is complicated due to "nonexistent" links feature {{{
function! s:add_target_syntax_ON(target, type) " {{{
let prefix0 = 'syntax match '.a:type.' `' let prefix0 = 'syntax match '.a:type.' `'
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
let prefix1 = 'syntax match '.a:type.'T `' let prefix1 = 'syntax match '.a:type.'T `'
let suffix1 = '` display contained' let suffix1 = '` display contained'
execute prefix0. a:target. suffix0 execute prefix0. a:target. suffix0
execute prefix1. a:target. suffix1 execute prefix1. a:target. suffix1
endfunction "}}} endfunction
function! s:add_target_syntax_OFF(target) " {{{
function! s:add_target_syntax_OFF(target)
let prefix0 = 'syntax match VimwikiNoExistsLink `' let prefix0 = 'syntax match VimwikiNoExistsLink `'
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,VimwikiLinkChar' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,VimwikiLinkChar'
let prefix1 = 'syntax match VimwikiNoExistsLinkT `' let prefix1 = 'syntax match VimwikiNoExistsLinkT `'
let suffix1 = '` display contained' let suffix1 = '` display contained'
execute prefix0. a:target. suffix0 execute prefix0. a:target. suffix0
execute prefix1. a:target. suffix1 execute prefix1. a:target. suffix1
endfunction "}}} endfunction
function! s:highlight_existing_links() "{{{
function! s:highlight_existing_links()
" Wikilink " Wikilink
" Conditional highlighting that depends on the existence of a wiki file or " Conditional highlighting that depends on the existence of a wiki file or
" directory is only available for *schemeless* wiki links " directory is only available for *schemeless* wiki links
" Links are set up upon BufEnter (see plugin/...) " Links are set up upon BufEnter (see plugin/...)
let safe_links = '\%('.vimwiki#base#file_pattern(b:existing_wikifiles) . let safe_links = '\%('.vimwiki#base#file_pattern(
\ '\%(#[^|]*\)\?\|#[^|]*\)' \ vimwiki#vars#get_bufferlocal('existing_wikifiles')) . '\%(#[^|]*\)\?\|#[^|]*\)'
" Wikilink Dirs set up upon BufEnter (see plugin/...) " Wikilink Dirs set up upon BufEnter (see plugin/...)
let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs) let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
" match [[URL]] " match [[URL]]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate1), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')),
\ safe_links, g:vimwiki_rxWikiLinkDescr, '') \ safe_links, vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
" match [[URL|DESCRIPTION]] " match [[URL|DESCRIPTION]]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate2), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')),
\ safe_links, g:vimwiki_rxWikiLinkDescr, '') \ safe_links, vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
" match {{URL}} " match {{URL}}
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiInclTemplate1), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate1')),
\ safe_links, g:vimwiki_rxWikiInclArgs, '') \ safe_links, vimwiki#vars#get_global('rxWikiInclArgs'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
" match {{URL|...}} " match {{URL|...}}
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiInclTemplate2), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate2')),
\ safe_links, g:vimwiki_rxWikiInclArgs, '') \ safe_links, vimwiki#vars#get_global('rxWikiInclArgs'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
" match [[DIRURL]] " match [[DIRURL]]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate1), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')),
\ safe_dirs, g:vimwiki_rxWikiLinkDescr, '') \ safe_dirs, vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
" match [[DIRURL|DESCRIPTION]] " match [[DIRURL|DESCRIPTION]]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate2), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')),
\ safe_dirs, g:vimwiki_rxWikiLinkDescr, '') \ safe_dirs, vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(target, 'VimwikiLink') call s:add_target_syntax_ON(target, 'VimwikiLink')
endfunction "}}} endfunction
" use max highlighting - could be quite slow if there are too many wikifiles " use max highlighting - could be quite slow if there are too many wikifiles
if VimwikiGet('maxhi') if vimwiki#vars#get_wikilocal('maxhi')
" WikiLink " WikiLink
call s:add_target_syntax_OFF(g:vimwiki_rxWikiLink) call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
" WikiIncl " WikiIncl
call s:add_target_syntax_OFF(g:vimwiki_rxWikiIncl) call s:add_target_syntax_OFF(vimwiki#vars#get_global('rxWikiIncl'))
" Subsequently, links verified on vimwiki's path are highlighted as existing " Subsequently, links verified on vimwiki's path are highlighted as existing
call s:highlight_existing_links() call s:highlight_existing_links()
else else
" Wikilink " Wikilink
call s:add_target_syntax_ON(g:vimwiki_rxWikiLink, 'VimwikiLink') call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink'), 'VimwikiLink')
" WikiIncl " WikiIncl
call s:add_target_syntax_ON(g:vimwiki_rxWikiIncl, 'VimwikiLink') call s:add_target_syntax_ON(vimwiki#vars#get_global('rxWikiIncl'), 'VimwikiLink')
endif endif
" Weblink " Weblink
call s:add_target_syntax_ON(g:vimwiki_rxWeblink, 'VimwikiLink') call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink'), 'VimwikiLink')
" WikiLink " WikiLink
" All remaining schemes are highlighted automatically " All remaining schemes are highlighted automatically
let s:rxSchemes = '\%('. let s:rxSchemes = '\%('.
\ join(split(g:vimwiki_schemes, '\s*,\s*'), '\|').'\|'. \ vimwiki#vars#get_global('schemes') . '\|'.
\ join(split(g:vimwiki_web_schemes1, '\s*,\s*'), '\|'). \ vimwiki#vars#get_global('web_schemes1').
\ '\):' \ '\):'
" a) match [[nonwiki-scheme-URL]] " a) match [[nonwiki-scheme-URL]]
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate1), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate1')),
\ s:rxSchemes.g:vimwiki_rxWikiLinkUrl, g:vimwiki_rxWikiLinkDescr, '') \ s:rxSchemes.vimwiki#vars#get_global('rxWikiLinkUrl'),
\ vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(s:target, 'VimwikiLink') call s:add_target_syntax_ON(s:target, 'VimwikiLink')
" b) match [[nonwiki-scheme-URL|DESCRIPTION]] " b) match [[nonwiki-scheme-URL|DESCRIPTION]]
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLinkTemplate2), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiLinkTemplate2')),
\ s:rxSchemes.g:vimwiki_rxWikiLinkUrl, g:vimwiki_rxWikiLinkDescr, '') \ s:rxSchemes.vimwiki#vars#get_global('rxWikiLinkUrl'),
\ vimwiki#vars#get_global('rxWikiLinkDescr'), '')
call s:add_target_syntax_ON(s:target, 'VimwikiLink') call s:add_target_syntax_ON(s:target, 'VimwikiLink')
" a) match {{nonwiki-scheme-URL}} " a) match {{nonwiki-scheme-URL}}
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiInclTemplate1), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate1')),
\ s:rxSchemes.g:vimwiki_rxWikiInclUrl, g:vimwiki_rxWikiInclArgs, '') \ s:rxSchemes.vimwiki#vars#get_global('rxWikiInclUrl'),
\ vimwiki#vars#get_global('rxWikiInclArgs'), '')
call s:add_target_syntax_ON(s:target, 'VimwikiLink') call s:add_target_syntax_ON(s:target, 'VimwikiLink')
" b) match {{nonwiki-scheme-URL}[{...}]} " b) match {{nonwiki-scheme-URL}[{...}]}
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiInclTemplate2), \ vimwiki#u#escape(vimwiki#vars#get_global('WikiInclTemplate2')),
\ s:rxSchemes.g:vimwiki_rxWikiInclUrl, g:vimwiki_rxWikiInclArgs, '') \ s:rxSchemes.vimwiki#vars#get_global('rxWikiInclUrl'),
\ vimwiki#vars#get_global('rxWikiInclArgs'), '')
call s:add_target_syntax_ON(s:target, 'VimwikiLink') call s:add_target_syntax_ON(s:target, 'VimwikiLink')
" }}}
" generic headers "{{{
if g:vimwiki_symH
"" symmetric
for s:i in range(1,6)
let g:vimwiki_rxH{s:i}_Template = repeat(g:vimwiki_rxH, s:i).' __Header__ '.repeat(g:vimwiki_rxH, s:i)
let g:vimwiki_rxH{s:i} = '^\s*'.g:vimwiki_rxH.'\{'.s:i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{'.s:i.'}\s*$'
let g:vimwiki_rxH{s:i}_Start = '^\s*'.g:vimwiki_rxH.'\{'.s:i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{'.s:i.'}\s*$'
let g:vimwiki_rxH{s:i}_End = '^\s*'.g:vimwiki_rxH.'\{1,'.s:i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{1,'.s:i.'}\s*$'
endfor
let g:vimwiki_rxHeader = '^\s*\('.g:vimwiki_rxH.'\{1,6}\)\zs[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']\ze\1\s*$'
else
" asymmetric
for s:i in range(1,6)
let g:vimwiki_rxH{s:i}_Template = repeat(g:vimwiki_rxH, s:i).' __Header__'
let g:vimwiki_rxH{s:i} = '^\s*'.g:vimwiki_rxH.'\{'.s:i.'}[^'.g:vimwiki_rxH.'].*$'
let g:vimwiki_rxH{s:i}_Start = '^\s*'.g:vimwiki_rxH.'\{'.s:i.'}[^'.g:vimwiki_rxH.'].*$'
let g:vimwiki_rxH{s:i}_End = '^\s*'.g:vimwiki_rxH.'\{1,'.s:i.'}[^'.g:vimwiki_rxH.'].*$'
endfor
let g:vimwiki_rxHeader = '^\s*\('.g:vimwiki_rxH.'\{1,6}\)\zs[^'.g:vimwiki_rxH.'].*\ze$'
endif
" Header levels, 1-6 " Header levels, 1-6
for s:i in range(1,6) for s:i in range(1,6)
execute 'syntax match VimwikiHeader'.s:i.' /'.g:vimwiki_rxH{s:i}.'/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,VimwikiLink,@Spell' execute 'syntax match VimwikiHeader'.s:i
execute 'syntax region VimwikiH'.s:i.'Folding start=/'.g:vimwiki_rxH{s:i}_Start. \ . ' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i, s:current_syntax).
\ '/ end=/'.g:vimwiki_rxH{s:i}_End.'/me=s-1 transparent fold' \ '/ 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 endfor
" }}}
let g:vimwiki_rxPreStart = '^\s*'.g:vimwiki_rxPreStart " possibly concealed chars
let g:vimwiki_rxPreEnd = '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
let g:vimwiki_rxMathStart = '^\s*'.g:vimwiki_rxMathStart
let g:vimwiki_rxMathEnd = '^\s*'.g:vimwiki_rxMathEnd.'\s*$'
" possibly concealed chars " {{{
let s:conceal = exists("+conceallevel") ? ' conceal' : '' let s:conceal = exists("+conceallevel") ? ' conceal' : ''
execute 'syn match VimwikiEqInChar contained /'.g:vimwiki_char_eqin.'/'.s:conceal execute 'syn match VimwikiEqInChar contained /'.
execute 'syn match VimwikiBoldChar contained /'.g:vimwiki_char_bold.'/'.s:conceal \ vimwiki#vars#get_syntaxlocal('char_eqin').'/'.s:conceal
execute 'syn match VimwikiItalicChar contained /'.g:vimwiki_char_italic.'/'.s:conceal execute 'syn match VimwikiBoldChar contained /'.
execute 'syn match VimwikiBoldItalicChar contained /'.g:vimwiki_char_bolditalic.'/'.s:conceal \ vimwiki#vars#get_syntaxlocal('char_bold').'/'.s:conceal
execute 'syn match VimwikiItalicBoldChar contained /'.g:vimwiki_char_italicbold.'/'.s:conceal execute 'syn match VimwikiItalicChar contained /'.
execute 'syn match VimwikiCodeChar contained /'.g:vimwiki_char_code.'/'.s:conceal \ vimwiki#vars#get_syntaxlocal('char_italic').'/'.s:conceal
execute 'syn match VimwikiDelTextChar contained /'.g:vimwiki_char_deltext.'/'.s:conceal execute 'syn match VimwikiBoldItalicChar contained /'.
execute 'syn match VimwikiSuperScript contained /'.g:vimwiki_char_superscript.'/'.s:conceal \ vimwiki#vars#get_syntaxlocal('char_bolditalic').'/'.s:conceal
execute 'syn match VimwikiSubScript contained /'.g:vimwiki_char_subscript.'/'.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' let s:options = ' contained transparent contains=NONE'
"
" A shortener for long URLs: LinkRest (a middle part of the URL) is concealed " 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 " VimwikiLinkRest group is left undefined if link shortening is not desired
if exists("+conceallevel") && g:vimwiki_url_maxsave > 0 if exists("+conceallevel") && vimwiki#vars#get_global('url_maxsave') > 0
let s:options .= s:conceal let s:options .= s:conceal
execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\+\ze' execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\+\ze'
\.'\%([/#?]\w\|\S\{'.g:vimwiki_url_maxsave.'}\)`'.' cchar=~'.s:options \.'\%([/#?]\w\|\S\{'.vimwiki#vars#get_global('url_maxsave').'}\)`'.' cchar=~'.s:options
endif endif
" VimwikiLinkChar is for syntax markers (and also URL when a description " VimwikiLinkChar is for syntax markers (and also URL when a description
" is present) and may be concealed " is present) and may be concealed
" conceal wikilinks " conceal wikilinks
execute 'syn match VimwikiLinkChar /'.s:rx_wikilink_prefix.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_prefix').'/'.s:options
execute 'syn match VimwikiLinkChar /'.s:rx_wikilink_suffix.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_suffix').'/'.s:options
execute 'syn match VimwikiLinkChar /'.s:rx_wikilink_prefix1.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_prefix1').'/'.s:options
execute 'syn match VimwikiLinkChar /'.s:rx_wikilink_suffix1.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rx_wikilink_suffix1').'/'.s:options
" conceal wikiincls " conceal wikiincls
execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclPrefix.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclPrefix').'/'.s:options
execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix').'/'.s:options
execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclPrefix1.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclPrefix1').'/'.s:options
execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix1.'/'.s:options execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix1').'/'.s:options
" }}}
" non concealed chars " {{{
execute 'syn match VimwikiHeaderChar contained /\%(^\s*'.g:vimwiki_rxH.'\+\)\|\%('.g:vimwiki_rxH.'\+\s*$\)/'
execute 'syn match VimwikiEqInCharT contained /'.g:vimwiki_char_eqin.'/'
execute 'syn match VimwikiBoldCharT contained /'.g:vimwiki_char_bold.'/'
execute 'syn match VimwikiItalicCharT contained /'.g:vimwiki_char_italic.'/'
execute 'syn match VimwikiBoldItalicCharT contained /'.g:vimwiki_char_bolditalic.'/'
execute 'syn match VimwikiItalicBoldCharT contained /'.g:vimwiki_char_italicbold.'/'
execute 'syn match VimwikiCodeCharT contained /'.g:vimwiki_char_code.'/'
execute 'syn match VimwikiDelTextCharT contained /'.g:vimwiki_char_deltext.'/'
execute 'syn match VimwikiSuperScriptT contained /'.g:vimwiki_char_superscript.'/'
execute 'syn match VimwikiSubScriptT contained /'.g:vimwiki_char_subscript.'/'
" Emoticons " non concealed chars
"syntax match VimwikiEmoticons /\%((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/ 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').'/'
execute 'syntax match VimwikiTodo /'. vimwiki#vars#get_global('rxTodo') .'/'
let g:vimwiki_rxTodo = '\C\%(TODO:\|DONE:\|STARTED:\|FIXME:\|FIXED:\|XXX:\)'
execute 'syntax match VimwikiTodo /'. g:vimwiki_rxTodo .'/'
" }}}
" main syntax groups {{{
" Tables " Tables
syntax match VimwikiTableRow /^\s*|.\+|\s*$/ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
\ transparent contains=VimwikiCellSeparator, \ transparent contains=VimwikiCellSeparator,
\ VimwikiLinkT, \ VimwikiLinkT,
\ VimwikiNoExistsLinkT, \ VimwikiNoExistsLinkT,
\ VimwikiEmoticons,
\ VimwikiTodo, \ VimwikiTodo,
\ VimwikiBoldT, \ VimwikiBoldT,
\ VimwikiItalicT, \ VimwikiItalicT,
@ -407,82 +251,110 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
syntax match VimwikiCellSeparator syntax match VimwikiCellSeparator
\ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained \ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained
" Lists
execute 'syntax match VimwikiList /'.g:vimwiki_rxListItemWithoutCB.'/'
execute 'syntax match VimwikiList /'.g:vimwiki_rxListDefine.'/'
execute 'syntax match VimwikiListTodo /'.g:vimwiki_rxListItem.'/'
if g:vimwiki_hl_cb_checked == 1 " Lists
execute 'syntax match VimwikiCheckBoxDone /'.g:vimwiki_rxListItemWithoutCB.'\s*\['.g:vimwiki_listsyms_list[-1].'\]\s.*$/ '. execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListItemWithoutCB').'/'
\ 'contains=VimwikiNoExistsLink,VimwikiLink,@Spell' execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListDefine').'/'
elseif g:vimwiki_hl_cb_checked == 2 execute 'syntax match VimwikiListTodo /'.vimwiki#vars#get_syntaxlocal('rxListItem').'/'
execute 'syntax match VimwikiCheckBoxDone /'.g:vimwiki_rxListItemAndChildren.'/ contains=VimwikiNoExistsLink,VimwikiLink,@Spell'
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 endif
execute 'syntax match VimwikiEqIn /'.g:vimwiki_rxEqIn.'/ contains=VimwikiEqInChar' execute 'syntax match VimwikiEqIn /'.vimwiki#vars#get_syntaxlocal('rxEqIn').
execute 'syntax match VimwikiEqInT /'.g:vimwiki_rxEqIn.'/ contained contains=VimwikiEqInCharT' \ '/ contains=VimwikiEqInChar'
execute 'syntax match VimwikiEqInT /'.vimwiki#vars#get_syntaxlocal('rxEqIn').
\ '/ contained contains=VimwikiEqInCharT'
execute 'syntax match VimwikiBold /'.g:vimwiki_rxBold.'/ contains=VimwikiBoldChar,@Spell' execute 'syntax match VimwikiBold /'.vimwiki#vars#get_syntaxlocal('rxBold').
execute 'syntax match VimwikiBoldT /'.g:vimwiki_rxBold.'/ contained contains=VimwikiBoldCharT,@Spell' \ '/ contains=VimwikiBoldChar,@Spell'
execute 'syntax match VimwikiBoldT /'.vimwiki#vars#get_syntaxlocal('rxBold').
\ '/ contained contains=VimwikiBoldCharT,@Spell'
execute 'syntax match VimwikiItalic /'.g:vimwiki_rxItalic.'/ contains=VimwikiItalicChar,@Spell' execute 'syntax match VimwikiItalic /'.vimwiki#vars#get_syntaxlocal('rxItalic').
execute 'syntax match VimwikiItalicT /'.g:vimwiki_rxItalic.'/ contained contains=VimwikiItalicCharT,@Spell' \ '/ contains=VimwikiItalicChar,@Spell'
execute 'syntax match VimwikiItalicT /'.vimwiki#vars#get_syntaxlocal('rxItalic').
\ '/ contained contains=VimwikiItalicCharT,@Spell'
execute 'syntax match VimwikiBoldItalic /'.g:vimwiki_rxBoldItalic.'/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell' execute 'syntax match VimwikiBoldItalic /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').
execute 'syntax match VimwikiBoldItalicT /'.g:vimwiki_rxBoldItalic.'/ contained contains=VimwikiBoldItalicChatT,VimwikiItalicBoldCharT,@Spell' \ '/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell'
execute 'syntax match VimwikiBoldItalicT /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').
\ '/ contained contains=VimwikiBoldItalicChatT,VimwikiItalicBoldCharT,@Spell'
execute 'syntax match VimwikiItalicBold /'.g:vimwiki_rxItalicBold.'/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell' execute 'syntax match VimwikiItalicBold /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').
execute 'syntax match VimwikiItalicBoldT /'.g:vimwiki_rxItalicBold.'/ contained contains=VimwikiBoldItalicCharT,VimsikiItalicBoldCharT,@Spell' \ '/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell'
execute 'syntax match VimwikiItalicBoldT /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').
\ '/ contained contains=VimwikiBoldItalicCharT,VimsikiItalicBoldCharT,@Spell'
execute 'syntax match VimwikiDelText /'.g:vimwiki_rxDelText.'/ contains=VimwikiDelTextChar,@Spell' execute 'syntax match VimwikiDelText /'.vimwiki#vars#get_syntaxlocal('rxDelText').
execute 'syntax match VimwikiDelTextT /'.g:vimwiki_rxDelText.'/ contained contains=VimwikiDelTextChar,@Spell' \ '/ contains=VimwikiDelTextChar,@Spell'
execute 'syntax match VimwikiDelTextT /'.vimwiki#vars#get_syntaxlocal('rxDelText').
\ '/ contained contains=VimwikiDelTextChar,@Spell'
execute 'syntax match VimwikiSuperScript /'.g:vimwiki_rxSuperScript.'/ contains=VimwikiSuperScriptChar,@Spell' execute 'syntax match VimwikiSuperScript /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').
execute 'syntax match VimwikiSuperScriptT /'.g:vimwiki_rxSuperScript.'/ contained contains=VimwikiSuperScriptCharT,@Spell' \ '/ contains=VimwikiSuperScriptChar,@Spell'
execute 'syntax match VimwikiSuperScriptT /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').
\ '/ contained contains=VimwikiSuperScriptCharT,@Spell'
execute 'syntax match VimwikiSubScript /'.g:vimwiki_rxSubScript.'/ contains=VimwikiSubScriptChar,@Spell' execute 'syntax match VimwikiSubScript /'.vimwiki#vars#get_syntaxlocal('rxSubScript').
execute 'syntax match VimwikiSubScriptT /'.g:vimwiki_rxSubScript.'/ contained contains=VimwikiSubScriptCharT,@Spell' \ '/ 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'
execute 'syntax match VimwikiCode /'.g:vimwiki_rxCode.'/ contains=VimwikiCodeChar'
execute 'syntax match VimwikiCodeT /'.g:vimwiki_rxCode.'/ contained contains=VimwikiCodeCharT'
" <hr> horizontal rule " <hr> horizontal rule
execute 'syntax match VimwikiHR /'.g:vimwiki_rxHR.'/' execute 'syntax match VimwikiHR /'.vimwiki#vars#get_syntaxlocal('rxHR').'/'
execute 'syntax region VimwikiPre start=/'.g:vimwiki_rxPreStart. execute 'syntax region VimwikiPre start=/'.vimwiki#vars#get_syntaxlocal('rxPreStart').
\ '/ end=/'.g:vimwiki_rxPreEnd.'/ contains=@Spell' \ '/ end=/'.vimwiki#vars#get_syntaxlocal('rxPreEnd').'/ contains=@Spell'
execute 'syntax region VimwikiMath start=/'.g:vimwiki_rxMathStart. execute 'syntax region VimwikiMath start=/'.vimwiki#vars#get_syntaxlocal('rxMathStart').
\ '/ end=/'.g:vimwiki_rxMathEnd.'/ contains=@Spell' \ '/ end=/'.vimwiki#vars#get_syntaxlocal('rxMathEnd').'/ contains=@Spell'
" placeholders " placeholders
syntax match VimwikiPlaceholder /^\s*%nohtml\s*$/ syntax match VimwikiPlaceholder /^\s*%nohtml\s*$/
syntax match VimwikiPlaceholder /^\s*%title\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite syntax match VimwikiPlaceholder
syntax match VimwikiPlaceholder /^\s*%date\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite \ /^\s*%title\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite
syntax match VimwikiPlaceholder /^\s*%template\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite syntax match VimwikiPlaceholder
\ /^\s*%date\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite
syntax match VimwikiPlaceholder
\ /^\s*%template\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite
syntax match VimwikiPlaceholderParam /.*/ contained syntax match VimwikiPlaceholderParam /.*/ contained
" html tags " html tags
if g:vimwiki_valid_html_tags != '' if vimwiki#vars#get_global('valid_html_tags') != ''
let s:html_tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|') let s:html_tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#' exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#'
execute 'syntax match VimwikiBold #\c<b>.\{-}</b># contains=VimwikiHTMLTag' execute 'syntax match VimwikiBold #\c<b>.\{-}</b># contains=VimwikiHTMLTag'
execute 'syntax match VimwikiItalic #\c<i>.\{-}</i># contains=VimwikiHTMLTag' execute 'syntax match VimwikiItalic #\c<i>.\{-}</i># contains=VimwikiHTMLTag'
execute 'syntax match VimwikiUnderline #\c<u>.\{-}</u># contains=VimwikiHTMLTag' execute 'syntax match VimwikiUnderline #\c<u>.\{-}</u># contains=VimwikiHTMLTag'
execute 'syntax match VimwikiComment /'.g:vimwiki_rxComment.'/ contains=@Spell' execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
\ '/ contains=@Spell,VimwikiTodo'
endif endif
" tags " tags
execute 'syntax match VimwikiTag /'.g:vimwiki_rxTags.'/' execute 'syntax match VimwikiTag /'.vimwiki#vars#get_syntaxlocal('rxTags').'/'
" }}}
" header groups highlighting "{{{
if g:vimwiki_hl_headers == 0 " header groups highlighting
if vimwiki#vars#get_global('hl_headers') == 0
" Strangely in default colorscheme Title group is not set to bold for cterm... " Strangely in default colorscheme Title group is not set to bold for cterm...
if !exists("g:colors_name") if !exists("g:colors_name")
hi Title cterm=bold hi Title cterm=bold
@ -491,19 +363,14 @@ if g:vimwiki_hl_headers == 0
execute 'hi def link VimwikiHeader'.s:i.' Title' execute 'hi def link VimwikiHeader'.s:i.' Title'
endfor endfor
else else
" default colors when headers of different levels are highlighted differently
" not making it yet another option; needed by ColorScheme autocommand
let g:vimwiki_hcolor_guifg_light = ['#aa5858','#507030','#1030a0','#103040','#505050','#636363']
let g:vimwiki_hcolor_ctermfg_light = ['DarkRed','DarkGreen','DarkBlue','Black','Black','Black']
let g:vimwiki_hcolor_guifg_dark = ['#e08090','#80e090','#6090e0','#c0c0f0','#e0e0f0','#f0f0f0']
let g:vimwiki_hcolor_ctermfg_dark = ['Red','Green','Blue','White','White','White']
for s:i in range(1,6) for s:i in range(1,6)
execute 'hi def VimwikiHeader'.s:i.' guibg=bg guifg='.g:vimwiki_hcolor_guifg_{&bg}[s:i-1].' gui=bold ctermfg='.g:vimwiki_hcolor_ctermfg_{&bg}[s:i-1].' term=bold cterm=bold' execute 'hi def VimwikiHeader'.s:i.' guibg=bg guifg='
\ .vimwiki#vars#get_global('hcolor_guifg_'.&bg)[s:i-1].' gui=bold ctermfg='
\ .vimwiki#vars#get_global('hcolor_ctermfg_'.&bg)[s:i-1].' term=bold cterm=bold'
endfor endfor
endif endif
"}}}
" syntax group highlighting "{{{
hi def link VimwikiMarkers Normal hi def link VimwikiMarkers Normal
@ -541,7 +408,6 @@ hi def link VimwikiLinkT VimwikiLink
hi def link VimwikiList Identifier hi def link VimwikiList Identifier
hi def link VimwikiListTodo VimwikiList hi def link VimwikiListTodo VimwikiList
hi def link VimwikiCheckBoxDone Comment hi def link VimwikiCheckBoxDone Comment
hi def link VimwikiEmoticons Character
hi def link VimwikiHR Identifier hi def link VimwikiHR Identifier
hi def link VimwikiTag Keyword hi def link VimwikiTag Keyword
@ -585,33 +451,37 @@ hi def link VimwikiCodeCharT VimwikiMarkers
hi def link VimwikiHeaderCharT VimwikiMarkers hi def link VimwikiHeaderCharT VimwikiMarkers
hi def link VimwikiLinkCharT VimwikiLinkT hi def link VimwikiLinkCharT VimwikiLinkT
hi def link VimwikiNoExistsLinkCharT VimwikiNoExistsLinkT hi def link VimwikiNoExistsLinkCharT VimwikiNoExistsLinkT
"}}}
" Load syntax-specific functionality " Load syntax-specific functionality
call vimwiki#u#reload_regexes_custom() call vimwiki#u#reload_regexes_custom()
" FIXME it now does not make sense to pretend there is a single syntax "vimwiki" " FIXME it now does not make sense to pretend there is a single syntax "vimwiki"
let b:current_syntax="vimwiki" let b:current_syntax="vimwiki"
" EMBEDDED syntax setup "{{{
let s:nested = VimwikiGet('nested_syntaxes') " EMBEDDED syntax setup
if VimwikiGet('automatic_nested_syntaxes') let s:nested = vimwiki#vars#get_wikilocal('nested_syntaxes')
if vimwiki#vars#get_wikilocal('automatic_nested_syntaxes')
let s:nested = extend(s:nested, vimwiki#base#detect_nested_syntax(), "keep") let s:nested = extend(s:nested, vimwiki#base#detect_nested_syntax(), "keep")
endif endif
if !empty(s:nested) if !empty(s:nested)
for [s:hl_syntax, s:vim_syntax] in items(s:nested) for [s:hl_syntax, s:vim_syntax] in items(s:nested)
call vimwiki#base#nested_syntax(s:vim_syntax, call vimwiki#base#nested_syntax(s:vim_syntax,
\ g:vimwiki_rxPreStart.'\%(.*[[:blank:][:punct:]]\)\?'. \ vimwiki#vars#get_syntaxlocal('rxPreStart').'\%(.*[[:blank:][:punct:]]\)\?'.
\ s:hl_syntax.'\%([[:blank:][:punct:]].*\)\?', \ s:hl_syntax.'\%([[:blank:][:punct:]].*\)\?',
\ g:vimwiki_rxPreEnd, 'VimwikiPre') \ vimwiki#vars#get_syntaxlocal('rxPreEnd'), 'VimwikiPre')
endfor endfor
endif endif
" LaTeX " LaTeX
call vimwiki#base#nested_syntax('tex', call vimwiki#base#nested_syntax('tex',
\ g:vimwiki_rxMathStart.'\%(.*[[:blank:][:punct:]]\)\?'. \ vimwiki#vars#get_syntaxlocal('rxMathStart').'\%(.*[[:blank:][:punct:]]\)\?'.
\ '\%([[:blank:][:punct:]].*\)\?', \ '\%([[:blank:][:punct:]].*\)\?',
\ g:vimwiki_rxMathEnd, 'VimwikiMath') \ vimwiki#vars#get_syntaxlocal('rxMathEnd'), 'VimwikiMath')
"}}}
syntax spell toplevel syntax spell toplevel

View File

@ -1,95 +1,110 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file " Vimwiki syntax file
" Desc: Defines default syntax " Description: Defines default syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" s:default_syntax is kind of a reference to the dict in
" g:vimwiki_syntax_variables['default']. It is used here simply as an
" abbreviation for the latter.
let s:default_syntax = g:vimwiki_syntax_variables['default']
" text: $ equation_inline $ " text: $ equation_inline $
let g:vimwiki_rxEqIn = '\$[^$`]\+\$' let s:default_syntax.rxEqIn = '\$[^$`]\+\$'
let g:vimwiki_char_eqin = '\$' let s:default_syntax.char_eqin = '\$'
" text: *strong* " text: *strong*
" let g:vimwiki_rxBold = '\*[^*]\+\*' " let s:default_syntax.rxBold = '\*[^*]\+\*'
let g:vimwiki_rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:default_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*'. \'\*'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\*'. \'\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bold = '*' let s:default_syntax.char_bold = '*'
" text: _emphasis_ " text: _emphasis_
" let g:vimwiki_rxItalic = '_[^_]\+_' " let s:default_syntax.rxItalic = '_[^_]\+_'
let g:vimwiki_rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:default_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_'. \'_'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'_'. \'_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italic = '_' let s:default_syntax.char_italic = '_'
" text: *_bold italic_* or _*italic bold*_ " text: *_bold italic_* or _*italic bold*_
let g:vimwiki_rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:default_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*_'. \'\*_'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'_\*'. \'_\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bolditalic = '\*_' let s:default_syntax.char_bolditalic = '\*_'
let g:vimwiki_rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:default_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_\*'. \'_\*'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\*_'. \'\*_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italicbold = '_\*' let s:default_syntax.char_italicbold = '_\*'
" text: `code` " text: `code`
let g:vimwiki_rxCode = '`[^`]\+`' let s:default_syntax.rxCode = '`[^`]\+`'
let g:vimwiki_char_code = '`' let s:default_syntax.char_code = '`'
" text: ~~deleted text~~ " text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~`]\+\~\~' let s:default_syntax.rxDelText = '\~\~[^~`]\+\~\~'
let g:vimwiki_char_deltext = '\~\~' let s:default_syntax.char_deltext = '\~\~'
" text: ^superscript^ " text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^`]\+\^' let s:default_syntax.rxSuperScript = '\^[^^`]\+\^'
let g:vimwiki_char_superscript = '^' let s:default_syntax.char_superscript = '^'
" text: ,,subscript,, " text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,`]\+,,' let s:default_syntax.rxSubScript = ',,[^,`]\+,,'
let g:vimwiki_char_subscript = ',,' let s:default_syntax.char_subscript = ',,'
" generic headers " generic headers
let g:vimwiki_rxH = '=' let s:default_syntax.rxH = '='
let g:vimwiki_symH = 1 let s:default_syntax.symH = 1
" <hr>, horizontal rule " <hr>, horizontal rule
let g:vimwiki_rxHR = '^-----*$' let s:default_syntax.rxHR = '^-----*$'
" Tables. Each line starts and ends with '|'; each cell is separated by '|' " Tables. Each line starts and ends with '|'; each cell is separated by '|'
let g:vimwiki_rxTableSep = '|' let s:default_syntax.rxTableSep = '|'
" Lists " Lists
"1 means multiple bullets, like * ** *** let s:default_syntax.bullet_types = ['-', '*', '#']
let g:vimwiki_bullet_types = { '-':0, '*':0, '#':0 } " 1 means the bullets can be repeatet to indicate the level, like * ** ***
let g:vimwiki_number_types = ['1)', '1.', 'i)', 'I)', 'a)', 'A)'] " 0 means the bullets stand on their own and the level is indicated by the indentation
let s:default_syntax.recurring_bullets = 0
let s:default_syntax.number_types = ['1)', '1.', 'i)', 'I)', 'a)', 'A)']
"this should contain at least one element "this should contain at least one element
"it is used for i_<C-L><C-J> among other things "it is used for i_<C-L><C-J> among other things
let g:vimwiki_list_markers = ['-', '1.', '*', 'I)', 'a)'] let s:default_syntax.list_markers = ['-', '1.', '*', 'I)', 'a)']
let g:vimwiki_rxListDefine = '::\(\s\|$\)' let s:default_syntax.rxListDefine = '::\(\s\|$\)'
call vimwiki#lst#setup_marker_infos()
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
" Preformatted text " Preformatted text
let g:vimwiki_rxPreStart = '{{{' let s:default_syntax.rxPreStart = '{{{'
let g:vimwiki_rxPreEnd = '}}}' let s:default_syntax.rxPreEnd = '}}}'
" Math block " Math block
let g:vimwiki_rxMathStart = '{{\$' let s:default_syntax.rxMathStart = '{{\$'
let g:vimwiki_rxMathEnd = '}}\$' let s:default_syntax.rxMathEnd = '}}\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let s:default_syntax.rxComment = '^\s*%%.*$'
let g:vimwiki_rxTags = '\%(^\|\s\)\@<=:\%([^:''[:space:]]\+:\)\+\%(\s\|$\)\@=' let s:default_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:''[:space:]]\+:\)\+\%(\s\|$\)\@='
" see also g:vimwiki_default_tag_search
let s:default_syntax.header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let s:default_syntax.header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let s:default_syntax.bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*'.
\ '[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*'.
\ '\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let s:default_syntax.tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let s:default_syntax.tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:'.
\ '\([^:[:space:]]\+:\)*\(\s\|$\)'

View File

@ -1,91 +1,104 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file " Vimwiki syntax file
" Desc: Defines markdown syntax " Description: Defines markdown syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" see the comments in vimwiki_default.vim for some info about this file
let s:markdown_syntax = g:vimwiki_syntax_variables['markdown']
" text: $ equation_inline $ " text: $ equation_inline $
let g:vimwiki_rxEqIn = '\$[^$`]\+\$' let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$'
let g:vimwiki_char_eqin = '\$' let s:markdown_syntax.char_eqin = '\$'
" text: *strong* " text: *strong*
" let g:vimwiki_rxBold = '\*[^*]\+\*' " let s:markdown_syntax.rxBold = '\*[^*]\+\*'
let g:vimwiki_rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*'. \'\*'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\*'. \'\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bold = '*' let s:markdown_syntax.char_bold = '*'
" text: _emphasis_ " text: _emphasis_
" let g:vimwiki_rxItalic = '_[^_]\+_' " let s:markdown_syntax.rxItalic = '_[^_]\+_'
let g:vimwiki_rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_'. \'_'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'_'. \'_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italic = '_' let s:markdown_syntax.char_italic = '_'
" text: *_bold italic_* or _*italic bold*_ " text: *_bold italic_* or _*italic bold*_
let g:vimwiki_rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*_'. \'\*_'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'_\*'. \'_\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bolditalic = '\*_' let s:markdown_syntax.char_bolditalic = '\*_'
let g:vimwiki_rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_\*'. \'_\*'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\*_'. \'\*_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italicbold = '_\*' let s:markdown_syntax.char_italicbold = '_\*'
" text: `code` " text: `code`
let g:vimwiki_rxCode = '`[^`]\+`' let s:markdown_syntax.rxCode = '`[^`]\+`'
let g:vimwiki_char_code = '`' let s:markdown_syntax.char_code = '`'
" text: ~~deleted text~~ " text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~`]\+\~\~' let s:markdown_syntax.rxDelText = '\~\~[^~`]\+\~\~'
let g:vimwiki_char_deltext = '\~\~' let s:markdown_syntax.char_deltext = '\~\~'
" text: ^superscript^ " text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^`]\+\^' let s:markdown_syntax.rxSuperScript = '\^[^^`]\+\^'
let g:vimwiki_char_superscript = '^' let s:markdown_syntax.char_superscript = '^'
" text: ,,subscript,, " text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,`]\+,,' let s:markdown_syntax.rxSubScript = ',,[^,`]\+,,'
let g:vimwiki_char_subscript = ',,' let s:markdown_syntax.char_subscript = ',,'
" generic headers " generic headers
let g:vimwiki_rxH = '#' let s:markdown_syntax.rxH = '#'
let g:vimwiki_symH = 0 let s:markdown_syntax.symH = 0
" <hr>, horizontal rule " <hr>, horizontal rule
let g:vimwiki_rxHR = '^-----*$' let s:markdown_syntax.rxHR = '^-----*$'
" Tables. Each line starts and ends with '|'; each cell is separated by '|' " Tables. Each line starts and ends with '|'; each cell is separated by '|'
let g:vimwiki_rxTableSep = '|' let s:markdown_syntax.rxTableSep = '|'
" Lists " Lists
let g:vimwiki_bullet_types = { '-':0, '*':0, '+':0 } let s:markdown_syntax.bullet_types = ['-', '*', '+']
let g:vimwiki_number_types = ['1.'] let s:markdown_syntax.recurring_bullets = 0
let g:vimwiki_list_markers = ['-', '*', '+', '1.'] let s:markdown_syntax.number_types = ['1.']
let g:vimwiki_rxListDefine = '::\%(\s\|$\)' let s:markdown_syntax.list_markers = ['-', '*', '+', '1.']
call vimwiki#lst#setup_marker_infos() let s:markdown_syntax.rxListDefine = '::\%(\s\|$\)'
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
" Preformatted text " Preformatted text
let g:vimwiki_rxPreStart = '```' let s:markdown_syntax.rxPreStart = '```'
let g:vimwiki_rxPreEnd = '```' let s:markdown_syntax.rxPreEnd = '```'
" Math block " Math block
let g:vimwiki_rxMathStart = '\$\$' let s:markdown_syntax.rxMathStart = '\$\$'
let g:vimwiki_rxMathEnd = '\$\$' let s:markdown_syntax.rxMathEnd = '\$\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let s:markdown_syntax.rxComment = '^\s*%%.*$\|<!--[^>]*-->'
let g:vimwiki_rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' let s:markdown_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
let s:markdown_syntax.header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
let s:markdown_syntax.header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
let s:markdown_syntax.bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs'.
\ '\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*'.
\ '\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let s:markdown_syntax.tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let s:markdown_syntax.tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:'.
\ '\([^:[:space:]]\+:\)*\(\s\|$\)'

View File

@ -1,329 +1,138 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki syntax file
" Desc: Special stuff for markdown syntax
" Home: https://github.com/vimwiki/vimwiki/
" LINKS: assume this is common to all syntaxes "{{{
" }}}
" -------------------------------------------------------------------------
" Load concrete Wiki syntax: sets regexes and templates for headers and links
" -------------------------------------------------------------------------
" LINKS: setup of larger regexes {{{
" LINKS: setup wikilink0 regexps {{{
" 0. [[URL]], or [[URL|DESCRIPTION]]
" 0a) match [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLink0 = g:vimwiki_rxWikiLink
" 0b) match URL within [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLink0MatchUrl = g:vimwiki_rxWikiLinkMatchUrl
" 0c) match DESCRIPTION within [[URL|DESCRIPTION]]
let g:vimwiki_rxWikiLink0MatchDescr = g:vimwiki_rxWikiLinkMatchDescr
" }}}
" LINKS: setup wikilink1 regexps {{{
" 1. [URL][], or [DESCRIPTION][URL]
let s:wikilink_md_prefix = '['
let s:wikilink_md_suffix = ']'
let s:wikilink_md_separator = ']['
let s:rx_wikilink_md_prefix = vimwiki#u#escape(s:wikilink_md_prefix)
let s:rx_wikilink_md_suffix = vimwiki#u#escape(s:wikilink_md_suffix)
let s:rx_wikilink_md_separator = vimwiki#u#escape(s:wikilink_md_separator)
" [URL][]
let g:vimwiki_WikiLink1Template1 = s:wikilink_md_prefix . '__LinkUrl__'.
\ s:wikilink_md_separator. s:wikilink_md_suffix
" [DESCRIPTION][URL]
let g:vimwiki_WikiLink1Template2 = s:wikilink_md_prefix. '__LinkDescription__'.
\ s:wikilink_md_separator. '__LinkUrl__'.
\ s:wikilink_md_suffix
"
let g:vimwiki_WikiLinkMatchUrlTemplate .=
\ '\|' .
\ s:rx_wikilink_md_prefix .
\ '.*' .
\ s:rx_wikilink_md_separator .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ s:rx_wikilink_md_suffix .
\ '\|' .
\ s:rx_wikilink_md_prefix .
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
\ s:rx_wikilink_md_separator .
\ s:rx_wikilink_md_suffix
let s:valid_chars = '[^\\\[\]]'
let g:vimwiki_rxWikiLink1Url = s:valid_chars.'\{-}'
let g:vimwiki_rxWikiLink1Descr = s:valid_chars.'\{-}'
let g:vimwiki_rxWikiLink1InvalidPrefix = '[\]\[]\@<!'
let g:vimwiki_rxWikiLink1InvalidSuffix = '[\]\[]\@!'
let s:rx_wikilink_md_prefix = g:vimwiki_rxWikiLink1InvalidPrefix.
\ s:rx_wikilink_md_prefix
let s:rx_wikilink_md_suffix = s:rx_wikilink_md_suffix.
\ g:vimwiki_rxWikiLink1InvalidSuffix
"
" 1. [URL][], [DESCRIPTION][URL]
" 1a) match [URL][], [DESCRIPTION][URL]
let g:vimwiki_rxWikiLink1 = s:rx_wikilink_md_prefix.
\ g:vimwiki_rxWikiLink1Url. s:rx_wikilink_md_separator.
\ s:rx_wikilink_md_suffix.
\ '\|'. s:rx_wikilink_md_prefix.
\ g:vimwiki_rxWikiLink1Descr.s:rx_wikilink_md_separator.
\ g:vimwiki_rxWikiLink1Url.s:rx_wikilink_md_suffix
" 1b) match URL within [URL][], [DESCRIPTION][URL]
let g:vimwiki_rxWikiLink1MatchUrl = s:rx_wikilink_md_prefix.
\ '\zs'. g:vimwiki_rxWikiLink1Url. '\ze'. s:rx_wikilink_md_separator.
\ s:rx_wikilink_md_suffix.
\ '\|'. s:rx_wikilink_md_prefix.
\ g:vimwiki_rxWikiLink1Descr. s:rx_wikilink_md_separator.
\ '\zs'. g:vimwiki_rxWikiLink1Url. '\ze'. s:rx_wikilink_md_suffix
" 1c) match DESCRIPTION within [DESCRIPTION][URL]
let g:vimwiki_rxWikiLink1MatchDescr = s:rx_wikilink_md_prefix.
\ '\zs'. g:vimwiki_rxWikiLink1Descr.'\ze'. s:rx_wikilink_md_separator.
\ g:vimwiki_rxWikiLink1Url.s:rx_wikilink_md_suffix
" }}}
" LINKS: Syntax helper {{{
let g:vimwiki_rxWikiLink1Prefix1 = s:rx_wikilink_md_prefix
let g:vimwiki_rxWikiLink1Suffix1 = s:rx_wikilink_md_separator.
\ g:vimwiki_rxWikiLink1Url.s:rx_wikilink_md_suffix
" }}}
" *. ANY wikilink {{{
" *a) match ANY wikilink
let g:vimwiki_rxWikiLink = ''.
\ g:vimwiki_rxWikiLink0.'\|'.
\ g:vimwiki_rxWikiLink1
" *b) match URL within ANY wikilink
let g:vimwiki_rxWikiLinkMatchUrl = ''.
\ g:vimwiki_rxWikiLink0MatchUrl.'\|'.
\ g:vimwiki_rxWikiLink1MatchUrl
" *c) match DESCRIPTION within ANY wikilink
let g:vimwiki_rxWikiLinkMatchDescr = ''.
\ g:vimwiki_rxWikiLink0MatchDescr.'\|'.
\ g:vimwiki_rxWikiLink1MatchDescr
" }}}
" LINKS: setup of wikiincl regexps {{{
" }}}
" LINKS: Syntax helper {{{
" }}}
" LINKS: Setup weblink0 regexps {{{
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
let g:vimwiki_rxWeblink0 = g:vimwiki_rxWeblink
" 0a) match URL within URL
let g:vimwiki_rxWeblinkMatchUrl0 = g:vimwiki_rxWeblinkMatchUrl
" 0b) match DESCRIPTION within URL
let g:vimwiki_rxWeblinkMatchDescr0 = g:vimwiki_rxWeblinkMatchDescr
" }}}
" LINKS: Setup weblink1 regexps {{{
let g:vimwiki_rxWeblink1Prefix = '['
let g:vimwiki_rxWeblink1Suffix = ')'
let g:vimwiki_rxWeblink1Separator = ']('
" [DESCRIPTION](URL)
let g:vimwiki_Weblink1Template = g:vimwiki_rxWeblink1Prefix . '__LinkDescription__'.
\ g:vimwiki_rxWeblink1Separator. '__LinkUrl__'.
\ g:vimwiki_rxWeblink1Suffix
let s:valid_chars = '[^\\]'
let g:vimwiki_rxWeblink1Prefix = vimwiki#u#escape(g:vimwiki_rxWeblink1Prefix)
let g:vimwiki_rxWeblink1Suffix = vimwiki#u#escape(g:vimwiki_rxWeblink1Suffix)
let g:vimwiki_rxWeblink1Separator = vimwiki#u#escape(g:vimwiki_rxWeblink1Separator)
let g:vimwiki_rxWeblink1Url = s:valid_chars.'\{-}'
let g:vimwiki_rxWeblink1Descr = s:valid_chars.'\{-}'
"
" " 2012-02-04 TODO not starting with [[ or ][ ? ... prefix = '[\[\]]\@<!\['
" 1. [DESCRIPTION](URL)
" 1a) match [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1 = g:vimwiki_rxWeblink1Prefix.
\ g:vimwiki_rxWeblink1Url.g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Descr.g:vimwiki_rxWeblink1Suffix
" 1b) match URL within [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1MatchUrl = g:vimwiki_rxWeblink1Prefix.
\ g:vimwiki_rxWeblink1Descr. g:vimwiki_rxWeblink1Separator.
\ '\zs'.g:vimwiki_rxWeblink1Url.'\ze'. g:vimwiki_rxWeblink1Suffix
" 1c) match DESCRIPTION within [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1MatchDescr = g:vimwiki_rxWeblink1Prefix.
\ '\zs'.g:vimwiki_rxWeblink1Descr.'\ze'. g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Url. g:vimwiki_rxWeblink1Suffix
" }}}
" Syntax helper {{{
" TODO: image links too !!
" let g:vimwiki_rxWeblink1Prefix1 = '!\?'. g:vimwiki_rxWeblink1Prefix
let g:vimwiki_rxWeblink1Prefix1 = g:vimwiki_rxWeblink1Prefix
let g:vimwiki_rxWeblink1Suffix1 = g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Url.g:vimwiki_rxWeblink1Suffix
" }}}
" *. ANY weblink {{{
" *a) match ANY weblink
let g:vimwiki_rxWeblink = ''.
\ g:vimwiki_rxWeblink1.'\|'.
\ g:vimwiki_rxWeblink0
" *b) match URL within ANY weblink
let g:vimwiki_rxWeblinkMatchUrl = ''.
\ g:vimwiki_rxWeblink1MatchUrl.'\|'.
\ g:vimwiki_rxWeblinkMatchUrl0
" *c) match DESCRIPTION within ANY weblink
let g:vimwiki_rxWeblinkMatchDescr = ''.
\ g:vimwiki_rxWeblink1MatchDescr.'\|'.
\ g:vimwiki_rxWeblinkMatchDescr0
" }}}
" LINKS: Setup anylink regexps {{{
let g:vimwiki_rxAnyLink = g:vimwiki_rxWikiLink.'\|'.
\ g:vimwiki_rxWikiIncl.'\|'.g:vimwiki_rxWeblink
" }}}
function! s:add_target_syntax_ON(target, type)
" LINKS: setup wikilink1 reference link definitions {{{
let g:vimwiki_rxMkdRef = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchDescr = '\[\zs'.g:vimwiki_rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchUrl = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
\ g:vimwiki_rxWeblink0.'\ze'
" }}}
" }}} end of Links
" LINKS: highlighting is complicated due to "nonexistent" links feature {{{
function! s:add_target_syntax_ON(target, type) " {{{
let prefix0 = 'syntax match '.a:type.' `' let prefix0 = 'syntax match '.a:type.' `'
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
let prefix1 = 'syntax match '.a:type.'T `' let prefix1 = 'syntax match '.a:type.'T `'
let suffix1 = '` display contained' let suffix1 = '` display contained'
execute prefix0. a:target. suffix0 execute prefix0. a:target. suffix0
execute prefix1. a:target. suffix1 execute prefix1. a:target. suffix1
endfunction "}}} endfunction
function! s:add_target_syntax_OFF(target, type) " {{{
function! s:add_target_syntax_OFF(target, type)
let prefix0 = 'syntax match VimwikiNoExistsLink `' let prefix0 = 'syntax match VimwikiNoExistsLink `'
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char' let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
let prefix1 = 'syntax match VimwikiNoExistsLinkT `' let prefix1 = 'syntax match VimwikiNoExistsLinkT `'
let suffix1 = '` display contained' let suffix1 = '` display contained'
execute prefix0. a:target. suffix0 execute prefix0. a:target. suffix0
execute prefix1. a:target. suffix1 execute prefix1. a:target. suffix1
endfunction "}}} endfunction
function! s:wrap_wikilink1_rx(target) "{{{
return g:vimwiki_rxWikiLink1InvalidPrefix.a:target.
\ g:vimwiki_rxWikiLink1InvalidSuffix
endfunction "}}}
function! s:existing_mkd_refs() "{{{ function! s:wrap_wikilink1_rx(target)
call vimwiki#markdown_base#reset_mkd_refs() return vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidPrefix') . a:target.
return keys(vimwiki#markdown_base#get_reflinks()) \ vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidSuffix')
endfunction "}}} endfunction
function! s:highlight_existing_links() "{{{
function! s:existing_mkd_refs()
return keys(vimwiki#markdown_base#scan_reflinks())
endfunction
function! s:highlight_existing_links()
" Wikilink1 " Wikilink1
" Conditional highlighting that depends on the existence of a wiki file or " Conditional highlighting that depends on the existence of a wiki file or
" directory is only available for *schemeless* wiki links " directory is only available for *schemeless* wiki links
" Links are set up upon BufEnter (see plugin/...) " Links are set up upon BufEnter (see plugin/...)
let safe_links = '\%('.vimwiki#base#file_pattern(b:existing_wikifiles) . let safe_links = '\%('.
\ vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikifiles')) .
\ '\%(#[^|]*\)\?\|#[^|]*\)' \ '\%(#[^|]*\)\?\|#[^|]*\)'
" Wikilink1 Dirs set up upon BufEnter (see plugin/...) " Wikilink1 Dirs set up upon BufEnter (see plugin/...)
let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs) let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
" Ref links are cached " Ref links are cached
let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs()) let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs())
" match [URL][] " match [URL][]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_links, g:vimwiki_rxWikiLink1Descr, '') \ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][URL] " match [DESCRIPTION][URL]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_links, g:vimwiki_rxWikiLink1Descr, '') \ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DIRURL][] " match [DIRURL][]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '') \ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][DIRURL] " match [DESCRIPTION][DIRURL]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '') \ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [MKDREF][] " match [MKDREF][]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '') \ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][MKDREF] " match [DESCRIPTION][MKDREF]
let target = vimwiki#base#apply_template( let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '') \ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
endfunction "}}} endfunction
" use max highlighting - could be quite slow if there are too many wikifiles " use max highlighting - could be quite slow if there are too many wikifiles
if VimwikiGet('maxhi') if vimwiki#vars#get_wikilocal('maxhi')
" WikiLink " WikiLink
call s:add_target_syntax_OFF(g:vimwiki_rxWikiLink1, 'VimwikiWikiLink1') call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
" Subsequently, links verified on vimwiki's path are highlighted as existing " Subsequently, links verified on vimwiki's path are highlighted as existing
call s:highlight_existing_links() call s:highlight_existing_links()
else else
" Wikilink " Wikilink
call s:add_target_syntax_ON(g:vimwiki_rxWikiLink1, 'VimwikiWikiLink1') call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
endif endif
" Weblink " Weblink
call s:add_target_syntax_ON(g:vimwiki_rxWeblink1, 'VimwikiWeblink1') call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1')
" WikiLink " WikiLink
" All remaining schemes are highlighted automatically " All remaining schemes are highlighted automatically
let s:rxSchemes = '\%('. let s:rxSchemes = '\%('.
\ join(split(g:vimwiki_schemes, '\s*,\s*'), '\|').'\|'. \ vimwiki#vars#get_global('schemes') . '\|'.
\ join(split(g:vimwiki_web_schemes1, '\s*,\s*'), '\|'). \ vimwiki#vars#get_global('web_schemes1').
\ '\):' \ '\):'
" a) match [nonwiki-scheme-URL] " a) match [nonwiki-scheme-URL]
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ s:rxSchemes.g:vimwiki_rxWikiLink1Url, g:vimwiki_rxWikiLink1Descr, '') \ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
" b) match [DESCRIPTION][nonwiki-scheme-URL] " b) match [DESCRIPTION][nonwiki-scheme-URL]
let s:target = vimwiki#base#apply_template( let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2), \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ s:rxSchemes.g:vimwiki_rxWikiLink1Url, g:vimwiki_rxWikiLink1Descr, '') \ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
" }}}
" generic headers "{{{
" Header levels, 1-6 " Header levels, 1-6
for s:i in range(1,6) for s:i in range(1,6)
execute 'syntax match VimwikiHeader'.s:i.' /'.g:vimwiki_rxH{s:i}.'/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell' execute 'syntax match VimwikiHeader'.s:i.' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i).
\ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'.
\ 'VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
endfor endfor
" }}}
" concealed chars " {{{
" concealed chars
if exists("+conceallevel") if exists("+conceallevel")
syntax conceal on syntax conceal on
endif endif
@ -334,24 +143,26 @@ syntax spell toplevel
" is present) and may be concealed " is present) and may be concealed
let s:options = ' contained transparent contains=NONE' let s:options = ' contained transparent contains=NONE'
" conceal wikilink1 " conceal wikilink1
execute 'syn match VimwikiWikiLink1Char /'.s:rx_wikilink_md_prefix.'/'.s:options execute 'syn match VimwikiWikiLink1Char /'.
execute 'syn match VimwikiWikiLink1Char /'.s:rx_wikilink_md_suffix.'/'.s:options \ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_prefix').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.g:vimwiki_rxWikiLink1Prefix1.'/'.s:options execute 'syn match VimwikiWikiLink1Char /'.
execute 'syn match VimwikiWikiLink1Char /'.g:vimwiki_rxWikiLink1Suffix1.'/'.s:options \ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_suffix').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Prefix1').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Suffix1').'/'.s:options
" conceal weblink1 " conceal weblink1
execute 'syn match VimwikiWeblink1Char "'.g:vimwiki_rxWeblink1Prefix1.'"'.s:options execute 'syn match VimwikiWeblink1Char "'.
execute 'syn match VimwikiWeblink1Char "'.g:vimwiki_rxWeblink1Suffix1.'"'.s:options \ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
execute 'syn match VimwikiWeblink1Char "'.
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
if exists("+conceallevel") if exists("+conceallevel")
syntax conceal off syntax conceal off
endif endif
" }}}
" non concealed chars " {{{
" }}}
" main syntax groups {{{
" Tables " Tables
syntax match VimwikiTableRow /^\s*|.\+|\s*$/ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
@ -360,7 +171,6 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
\ VimwikiWeblink1T, \ VimwikiWeblink1T,
\ VimwikiWikiLink1T, \ VimwikiWikiLink1T,
\ VimwikiNoExistsLinkT, \ VimwikiNoExistsLinkT,
\ VimwikiEmoticons,
\ VimwikiTodo, \ VimwikiTodo,
\ VimwikiBoldT, \ VimwikiBoldT,
\ VimwikiItalicT, \ VimwikiItalicT,
@ -373,22 +183,12 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
\ VimwikiEqInT, \ VimwikiEqInT,
\ @Spell \ @Spell
" }}}
" header groups highlighting "{{{
"}}}
" syntax group highlighting "{{{ " syntax group highlighting
hi def link VimwikiWeblink1 VimwikiLink hi def link VimwikiWeblink1 VimwikiLink
hi def link VimwikiWeblink1T VimwikiLink hi def link VimwikiWeblink1T VimwikiLink
hi def link VimwikiWikiLink1 VimwikiLink hi def link VimwikiWikiLink1 VimwikiLink
hi def link VimwikiWikiLink1T VimwikiLink hi def link VimwikiWikiLink1T VimwikiLink
"}}}
" EMBEDDED syntax setup "{{{
"}}}
"

View File

@ -1,72 +1,85 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file " Vimwiki syntax file
" Desc: Defines mediaWiki syntax " Description: Defines mediaWiki syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" see the comments in vimwiki_default.vim for some info about this file
let s:media_syntax = g:vimwiki_syntax_variables['media']
" text: $ equation_inline $ " text: $ equation_inline $
let g:vimwiki_rxEqIn = '\$[^$`]\+\$' let s:media_syntax.rxEqIn = '\$[^$`]\+\$'
let g:vimwiki_char_eqin = '\$' let s:media_syntax.char_eqin = '\$'
" text: '''strong''' " text: '''strong'''
let g:vimwiki_rxBold = "'''[^']\\+'''" let s:media_syntax.rxBold = "'''[^']\\+'''"
let g:vimwiki_char_bold = "'''" let s:media_syntax.char_bold = "'''"
" text: ''emphasis'' " text: ''emphasis''
let g:vimwiki_rxItalic = "''[^']\\+''" let s:media_syntax.rxItalic = "''[^']\\+''"
let g:vimwiki_char_italic = "''" let s:media_syntax.char_italic = "''"
" text: '''''strong italic''''' " text: '''''strong italic'''''
let g:vimwiki_rxBoldItalic = "'''''[^']\\+'''''" let s:media_syntax.rxBoldItalic = "'''''[^']\\+'''''"
let g:vimwiki_rxItalicBold = g:vimwiki_rxBoldItalic let s:media_syntax.rxItalicBold = s:media_syntax.rxBoldItalic
let g:vimwiki_char_bolditalic = "'''''" let s:media_syntax.char_bolditalic = "'''''"
let g:vimwiki_char_italicbold = g:vimwiki_char_bolditalic let s:media_syntax.char_italicbold = s:media_syntax.char_bolditalic
" text: `code` " text: `code`
let g:vimwiki_rxCode = '`[^`]\+`' let s:media_syntax.rxCode = '`[^`]\+`'
let g:vimwiki_char_code = '`' let s:media_syntax.char_code = '`'
" text: ~~deleted text~~ " text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~]\+\~\~' let s:media_syntax.rxDelText = '\~\~[^~]\+\~\~'
let g:vimwiki_char_deltext = '\~\~' let s:media_syntax.char_deltext = '\~\~'
" text: ^superscript^ " text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^]\+\^' let s:media_syntax.rxSuperScript = '\^[^^]\+\^'
let g:vimwiki_char_superscript = '^' let s:media_syntax.char_superscript = '^'
" text: ,,subscript,, " text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,]\+,,' let s:media_syntax.rxSubScript = ',,[^,]\+,,'
let g:vimwiki_char_subscript = ',,' let s:media_syntax.char_subscript = ',,'
" generic headers " generic headers
let g:vimwiki_rxH = '=' let s:media_syntax.rxH = '='
let g:vimwiki_symH = 1 let s:media_syntax.symH = 1
" <hr>, horizontal rule " <hr>, horizontal rule
let g:vimwiki_rxHR = '^-----*$' let s:media_syntax.rxHR = '^-----*$'
" Tables. Each line starts and ends with '|'; each cell is separated by '|' " Tables. Each line starts and ends with '|'; each cell is separated by '|'
let g:vimwiki_rxTableSep = '|' let s:media_syntax.rxTableSep = '|'
" Lists " Lists
let g:vimwiki_bullet_types = { '*':1, '#':1 } let s:media_syntax.bullet_types = ['*', '#']
let g:vimwiki_number_types = [] let s:media_syntax.recurring_bullets = 1
let g:vimwiki_list_markers = ['*', '#'] let s:media_syntax.number_types = []
let g:vimwiki_rxListDefine = '^\%(;\|:\)\s' let s:media_syntax.list_markers = ['*', '#']
call vimwiki#lst#setup_marker_infos() let s:media_syntax.rxListDefine = '^\%(;\|:\)\s'
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
let g:vimwiki_rxListItemAndChildren = '^\('.g:vimwiki_rxListBullet.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\%('.g:vimwiki_rxListBullet.'\).*\|^$\|\s.*\)\)*'
" Preformatted text " Preformatted text
let g:vimwiki_rxPreStart = '<pre>' let s:media_syntax.rxPreStart = '<pre>'
let g:vimwiki_rxPreEnd = '<\/pre>' let s:media_syntax.rxPreEnd = '<\/pre>'
" Math block " Math block
let g:vimwiki_rxMathStart = '{{\$' let s:media_syntax.rxMathStart = '{{\$'
let g:vimwiki_rxMathEnd = '}}\$' let s:media_syntax.rxMathEnd = '}}\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let s:media_syntax.rxComment = '^\s*%%.*$'
let g:vimwiki_rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' let s:media_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
let s:media_syntax.header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let s:media_syntax.header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let s:media_syntax.bold_search = "'''\\zs[^']\\+\\ze'''"
let s:media_syntax.bold_match = '''''''__Text__'''''''
" ^- this strange looking thing is equivalent to "'''__Text__'''" but since we later
" want to call escape() on this string, we must keep it in single quotes
let s:media_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let s:media_syntax.tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let s:media_syntax.tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:'.
\ '\([^:[:space:]]\+:\)*\(\s\|$\)'