Version 0.9.8

* NEW: Rename g:vimwiki_fold_empty_lines to g:vimwiki_fold_trailing_empty_lines.
* NEW: One can use - along with * to start unordered list item.
* NEW: List items could be started from the first column.  As a result some
  limitations appeared:
    * a space after *, - or # for a list item is mandatory.
    * g:vimwiki_fold_trailing_empty_lines if set to 0 folds one trailing
      empty line.
* NEW: Folding is off by default. Use g:vimwiki_folding to enable it.
* NEW: Speed up vimwiki's folding a bit. Should lag a bit less in a long todo lists.
* NEW: Centered headers. Start header with at least one space to make it html centered.
* NEW: Change in default css: header's colors.
* NEW: Vimwiki is aware of GetLatestVimScripts now.
* FIX: Use <del> tag instead of custom <span class="strike"> in html.
* FIX: There are no text styling in htmlized quoted text.
* FIX: set default value of g:vimwiki_fold_lists to 0 as written in this help.
* FIX: Issue 33: Folded list items have wrong indentation when 'tabs' are used.
* FIX: Issue 34: vimwiki#subdir got wrong dir when VimwikiGet('path') is a
  symbolic link. Thanks lilydjwg for the patch.
* FIX: Issue 28: todo-list auto-indent enhancement. New item should always be unchecked.
* FIX: Issue 36: Change the name of the :Search command to :VimwikiSearch
  as it conflicts with MultipleSearch. Alias :VWS is also available.
* NEW: You can generate 'Table of contents' of your wiki page. See :h vimwiki-toc for details.
This commit is contained in:
Maxim Kim 2010-01-20 00:00:00 +00:00 committed by Able Scraper
parent 66c3d9df83
commit 3393774904
10 changed files with 4593 additions and 4361 deletions

676
autoload/vimwiki.vim Normal file
View File

@ -0,0 +1,676 @@
" Vimwiki autoload plugin file
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
if exists("g:loaded_vimwiki_auto") || &cp
finish
endif
let g:loaded_vimwiki_auto = 1
if has("win32")
let s:os_sep = '\'
else
let s:os_sep = '/'
endif
let s:badsymbols = '['.g:vimwiki_badsyms.g:vimwiki_stripsym.'<>|?*:"]'
" MISC helper functions {{{
" This function is double defined.
" TODO: refactor common functions into new module.
function! s:chomp_slash(str) "{{{
return substitute(a:str, '[/\\]\+$', '', '')
endfunction "}}}
function! vimwiki#mkdir(path) "{{{
let path = expand(a:path)
if !isdirectory(path) && exists("*mkdir")
let path = s:chomp_slash(path)
call mkdir(path, "p")
endif
endfunction
" }}}
function! vimwiki#safe_link(string) "{{{
return substitute(a:string, s:badsymbols, g:vimwiki_stripsym, 'g')
endfunction
"}}}
function! vimwiki#unsafe_link(string) "{{{
return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
endfunction
"}}}
function! vimwiki#subdir(path, filename)"{{{
let path = expand(a:path)
let filename = expand(a:filename)
let idx = 0
while path[idx] == filename[idx]
let idx = idx + 1
endwhile
let p = split(strpart(filename, idx), '[/\\]')
let res = join(p[:-2], s:os_sep)
if len(res) > 0
let res = res.s:os_sep
endif
return res
endfunction"}}}
function! vimwiki#current_subdir()"{{{
return vimwiki#subdir(VimwikiGet('path'), expand('%:p'))
endfunction"}}}
function! s:filename(link) "{{{
let result = vimwiki#safe_link(a:link)
if a:link =~ '|'
let result = vimwiki#safe_link(split(a:link, '|')[0])
elseif a:link =~ ']['
let result = vimwiki#safe_link(split(a:link, '][')[0])
endif
return result
endfunction
" }}}
function! s:is_wiki_word(str) "{{{
if a:str =~ g:vimwiki_word1 && a:str !~ '[[:space:]\\/]'
return 1
endif
return 0
endfunction
" }}}
function! s:edit_file(command, filename) "{{{
let fname = escape(a:filename, '% ')
call vimwiki#mkdir(fnamemodify(a:filename, ":p:h"))
execute a:command.' '.fname
endfunction
" }}}
function! s:search_word(wikiRx, cmd) "{{{
let match_line = search(a:wikiRx, 's'.a:cmd)
if match_line == 0
echomsg "vimwiki: Wiki link not found."
endif
endfunction
" }}}
function! s:get_word_at_cursor(wikiRX) "{{{
let col = col('.') - 1
let line = getline('.')
let ebeg = -1
let cont = match(line, a:wikiRX, 0)
while (ebeg >= 0 || (0 <= cont) && (cont <= col))
let contn = matchend(line, a:wikiRX, cont)
if (cont <= col) && (col < contn)
let ebeg = match(line, a:wikiRX, cont)
let elen = contn - ebeg
break
else
let cont = match(line, a:wikiRX, contn)
endif
endwh
if ebeg >= 0
return strpart(line, ebeg, elen)
else
return ""
endif
endf "}}}
function! s:strip_word(word) "{{{
let result = a:word
if strpart(a:word, 0, 2) == "[["
" get rid of [[ and ]]
let w = strpart(a:word, 2, strlen(a:word)-4)
if w =~ '|'
" we want "link" from [[link|link desc]]
let w = split(w, "|")[0]
elseif w =~ ']['
" we want "link" from [[link][link desc]]
let w = split(w, "][")[0]
endif
let result = vimwiki#safe_link(w)
endif
return result
endfunction
" }}}
function! s:is_link_to_non_wiki_file(word) "{{{
" Check if word is link to a non-wiki file.
" The easiest way is to check if it has extension like .txt or .html
if a:word =~ '\.\w\{1,4}$'
return 1
endif
return 0
endfunction
" }}}
function! s:print_wiki_list() "{{{
let idx = 0
while idx < len(g:vimwiki_list)
if idx == g:vimwiki_current_idx
let sep = ' * '
echohl PmenuSel
else
let sep = ' '
echohl None
endif
echo (idx + 1).sep.VimwikiGet('path', idx)
let idx += 1
endwhile
echohl None
endfunction
" }}}
function! s:wiki_select(wnum)"{{{
if a:wnum < 1 || a:wnum > len(g:vimwiki_list)
return
endif
let b:vimwiki_idx = g:vimwiki_current_idx
let g:vimwiki_current_idx = a:wnum - 1
endfunction
" }}}
function! s:update_wiki_link(fname, old, new) " {{{
echo "Updating links in ".a:fname
let has_updates = 0
let dest = []
for line in readfile(a:fname)
if !has_updates && match(line, a:old) != -1
let has_updates = 1
endif
call add(dest, substitute(line, a:old, escape(a:new, "&"), "g"))
endfor
" add exception handling...
if has_updates
call rename(a:fname, a:fname.'#vimwiki_upd#')
call writefile(dest, a:fname)
call delete(a:fname.'#vimwiki_upd#')
endif
endfunction
" }}}
function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g')
let new_fname = a:new_fname
if !s:is_wiki_word(new_fname)
let new_fname = '[['.new_fname.']]'
endif
if !s:is_wiki_word(old_fname)
let old_fname = '\[\['.vimwiki#unsafe_link(old_fname).
\ '\%(|.*\)\?\%(\]\[.*\)\?\]\]'
else
let old_fname = '\<'.old_fname.'\>'
endif
let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
for fname in files
call s:update_wiki_link(fname, old_fname, new_fname)
endfor
endfunction
" }}}
function! s:tail_name(fname) "{{{
let result = substitute(a:fname, ":", "__colon__", "g")
let result = fnamemodify(result, ":t:r")
let result = substitute(result, "__colon__", ":", "g")
return result
endfunction "}}}
function! s:update_wiki_links(old_fname, new_fname) " {{{
let old_fname = s:tail_name(a:old_fname)
let new_fname = s:tail_name(a:new_fname)
let subdirs = split(a:old_fname, '[/\\]')[: -2]
" TODO: Use Dictionary here...
let dirs_keys = ['']
let dirs_vals = ['']
if len(subdirs) > 0
let dirs_keys = ['']
let dirs_vals = [join(subdirs, '/').'/']
let idx = 0
while idx < len(subdirs) - 1
call add(dirs_keys, join(subdirs[: idx], '/').'/')
call add(dirs_vals, join(subdirs[idx+1 :], '/').'/')
let idx = idx + 1
endwhile
call add(dirs_keys,join(subdirs, '/').'/')
call add(dirs_vals, '')
endif
let idx = 0
while idx < len(dirs_keys)
let dir = dirs_keys[idx]
let new_dir = dirs_vals[idx]
call s:update_wiki_links_dir(dir,
\ new_dir.old_fname, new_dir.new_fname)
let idx = idx + 1
endwhile
endfunction
" }}}
function! s:get_wiki_buffers() "{{{
let blist = []
let bcount = 1
while bcount<=bufnr("$")
if bufexists(bcount)
let bname = fnamemodify(bufname(bcount), ":p")
if bname =~ VimwikiGet('ext')."$"
let bitem = [bname, getbufvar(bname, "vimwiki_prev_word")]
call add(blist, bitem)
endif
endif
let bcount = bcount + 1
endwhile
return blist
endfunction
" }}}
function! s:open_wiki_buffer(item) "{{{
call s:edit_file('e', a:item[0])
if !empty(a:item[1])
call setbufvar(a:item[0], "vimwiki_prev_word", a:item[1])
endif
endfunction
" }}}
" }}}
" SYNTAX highlight {{{
function! vimwiki#WikiHighlightWords() "{{{
" search all wiki files in 'path' and its subdirs.
let subdir = vimwiki#current_subdir()
let wikies = glob(VimwikiGet('path').subdir.'**/*'.VimwikiGet('ext'))
" remove .wiki extensions
let wikies = substitute(wikies, '\'.VimwikiGet('ext'), "", "g")
let g:vimwiki_wikiwords = split(wikies, '\n')
" remove backup files (.wiki~)
call filter(g:vimwiki_wikiwords, 'v:val !~ ''.*\~$''')
" remove paths
let rem_path = escape(expand(VimwikiGet('path')).subdir, '\')
call map(g:vimwiki_wikiwords, 'substitute(v:val, rem_path, "", "g")')
" Links with subdirs should be highlighted for linux and windows separators
" Change \ or / to [/\\]
let os_p = '[/\\]'
let os_p2 = escape(os_p, '\')
call map(g:vimwiki_wikiwords, 'substitute(v:val, os_p, os_p2, "g")')
for word in g:vimwiki_wikiwords
if g:vimwiki_camel_case &&
\ word =~ g:vimwiki_word1 && !s:is_link_to_non_wiki_file(word)
execute 'syntax match VimwikiWord /\%(^\|[^!]\)\@<=\<'.word.'\>/'
endif
execute 'syntax match VimwikiWord /\[\[\<'.
\ vimwiki#unsafe_link(word).
\ '\>\%(|\+.*\)*\]\]/'
execute 'syntax match VimwikiWord /\[\[\<'.
\ vimwiki#unsafe_link(word).
\ '\>\]\[.\+\]\]/'
endfor
execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/'
execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/'
endfunction
" }}}
function! vimwiki#hl_exists(hl)"{{{
if !hlexists(a:hl)
return 0
endif
redir => hlstatus
exe "silent hi" a:hl
redir END
return (hlstatus !~ "cleared")
endfunction
"}}}
function! vimwiki#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
" From http://vim.wikia.com/wiki/VimTip857
let ft=toupper(a:filetype)
let group='textGroup'.ft
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
" do nothing if b:current_syntax is defined.
unlet b:current_syntax
endif
" Some syntax files set up iskeyword which might scratch vimwiki a bit.
" Let us save and restore it later.
" let b:skip_set_iskeyword = 1
let is_keyword = &iskeyword
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
let &iskeyword = is_keyword
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
else
unlet b:current_syntax
endif
execute 'syntax region textSnip'.ft.'
\ matchgroup='.a:textSnipHl.'
\ start="'.a:start.'" end="'.a:end.'"
\ contains=@'.group
endfunction "}}}
"}}}
" WIKI functions {{{
function! vimwiki#WikiNextWord() "{{{
call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, '')
endfunction
" }}}
function! vimwiki#WikiPrevWord() "{{{
call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, 'b')
endfunction
" }}}
function! vimwiki#WikiFollowWord(split) "{{{
if a:split == "split"
let cmd = ":split "
elseif a:split == "vsplit"
let cmd = ":vsplit "
else
let cmd = ":e "
endif
let word = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWikiWord))
if word == ""
let weblink = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWeblink))
if weblink != ""
call VimwikiWeblinkHandler(weblink)
else
execute "normal! \n"
endif
return
endif
if s:is_link_to_non_wiki_file(word)
call s:edit_file(cmd, word)
else
let vimwiki_prev_word = [expand('%:p'), getpos('.')]
let subdir = vimwiki#current_subdir()
call s:edit_file(cmd, VimwikiGet('path').subdir.word.VimwikiGet('ext'))
let b:vimwiki_prev_word = vimwiki_prev_word
endif
endfunction
" }}}
function! vimwiki#WikiGoBackWord() "{{{
if exists("b:vimwiki_prev_word")
" go back to saved WikiWord
let prev_word = b:vimwiki_prev_word
execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
call setpos('.', prev_word[1])
endif
endfunction
" }}}
function! vimwiki#WikiGoHome(index) "{{{
call s:wiki_select(a:index)
call vimwiki#mkdir(VimwikiGet('path'))
try
execute ':e '.fnameescape(
\ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext'))
catch /E37/ " catch 'No write since last change' error
" this is really unsecure!!!
execute ':'.VimwikiGet('gohome').' '.
\ VimwikiGet('path').
\ VimwikiGet('index').
\ VimwikiGet('ext')
catch /E325/ " catch 'ATTENTION' error (:h E325)
endtry
endfunction
"}}}
function! vimwiki#WikiDeleteWord() "{{{
"" file system funcs
"" Delete WikiWord you are in from filesystem
let val = input('Delete ['.expand('%').'] (y/n)? ', "")
if val != 'y'
return
endif
let fname = expand('%:p')
try
call delete(fname)
catch /.*/
echomsg 'vimwiki: Cannot delete "'.expand('%:t:r').'"!'
return
endtry
execute "bdelete! ".escape(fname, " ")
" reread buffer => deleted WikiWord should appear as non-existent
if expand('%:p') != ""
execute "e"
endif
endfunction
"}}}
function! vimwiki#WikiRenameWord() "{{{
"" Rename WikiWord, update all links to renamed WikiWord
let subdir = vimwiki#current_subdir()
let old_fname = subdir.expand('%:t')
" there is no file (new one maybe)
if glob(expand('%:p')) == ''
echomsg 'vimwiki: Cannot rename "'.expand('%:p').
\'". It does not exist! (New file? Save it before renaming.)'
return
endif
let val = input('Rename "'.expand('%:t:r').'" (y/n)? ', "")
if val!='y'
return
endif
let new_link = input('Enter new name: ', "")
if new_link =~ '[/\\]'
" It is actually doable but I do not have free time to do it.
echomsg 'vimwiki: Cannot rename to a filename with path!'
return
endif
let new_link = subdir.new_link
" check new_fname - it should be 'good', not empty
if substitute(new_link, '\s', '', 'g') == ''
echomsg 'vimwiki: Cannot rename to an empty filename!'
return
endif
if s:is_link_to_non_wiki_file(new_link)
echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!'
return
endif
let new_link = s:strip_word(new_link)
let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext')
" do not rename if word with such name exists
let fname = glob(new_fname)
if fname != ''
echomsg 'vimwiki: Cannot rename to "'.new_fname.
\ '". File with that name exist!'
return
endif
" rename WikiWord file
try
echomsg "Renaming ".VimwikiGet('path').old_fname." to ".new_fname
let res = rename(expand('%:p'), expand(new_fname))
if res != 0
throw "Cannot rename!"
end
catch /.*/
echomsg 'vimwiki: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"'
return
endtry
let &buftype="nofile"
let cur_buffer = [expand('%:p'),
\getbufvar(expand('%:p'), "vimwiki_prev_word")]
let blist = s:get_wiki_buffers()
" save wiki buffers
for bitem in blist
execute ':b '.escape(bitem[0], ' ')
execute ':update'
endfor
execute ':b '.escape(cur_buffer[0], ' ')
" remove wiki buffers
for bitem in blist
execute 'bwipeout '.escape(bitem[0], ' ')
endfor
let setting_more = &more
setlocal nomore
" update links
call s:update_wiki_links(old_fname, new_link)
" restore wiki buffers
for bitem in blist
if bitem[0] != cur_buffer[0]
call s:open_wiki_buffer(bitem)
endif
endfor
call s:open_wiki_buffer([new_fname,
\ cur_buffer[1]])
" execute 'bwipeout '.escape(cur_buffer[0], ' ')
echomsg old_fname." is renamed to ".new_fname
let &more = setting_more
endfunction
" }}}
function! vimwiki#WikiUISelect()"{{{
call s:print_wiki_list()
let idx = input("Select Wiki (specify number): ")
if idx == ""
return
endif
call vimwiki#WikiGoHome(idx)
endfunction
"}}}
" }}}
" TEXT OBJECTS functions {{{
function! vimwiki#TO_header(inner, visual) "{{{
if !search('^\(=\+\)[^=]\+\1\s*$', 'bcW')
return
endif
let sel_start = line("'<")
let sel_end = line("'>")
let block_start = line(".")
let advance = 0
let level = vimwiki#count_first_sym(getline('.'))
let is_header_selected = sel_start == block_start
\ && sel_start != sel_end
if a:visual && is_header_selected
if level > 1
let level -= 1
call search('^\(=\{'.level.'\}\)[^=]\+\1\s*$', 'bcW')
else
let advance = 1
endif
endif
normal! V
if a:visual && is_header_selected
call cursor(sel_end + advance, 0)
endif
if search('^\(=\{1,'.level.'}\)[^=]\+\1\s*$', 'W')
call cursor(line('.') - 1, 0)
else
call cursor(line('$'), 0)
endif
if a:inner && getline(line('.')) =~ '^\s*$'
let lnum = prevnonblank(line('.') - 1)
call cursor(lnum, 0)
endif
endfunction
"}}}
function! vimwiki#count_first_sym(line) "{{{
let first_sym = matchstr(a:line, '\S')
return len(matchstr(a:line, first_sym.'\+'))
endfunction "}}}
function! vimwiki#AddHeaderLevel() "{{{
let lnum = line('.')
let line = getline(lnum)
if line =~ '^\s*$'
return
endif
if line =~ '^\s*\(=\+\).\+\1\s*$'
let level = vimwiki#count_first_sym(line)
if level < 6
let line = substitute(line, '\(=\+\).\+\1', '=&=', '')
call setline(lnum, line)
endif
else
let line = substitute(line, '^\s*', '&= ', '')
let line = substitute(line, '\s*$', ' =&', '')
call setline(lnum, line)
endif
endfunction
"}}}
function! vimwiki#RemoveHeaderLevel() "{{{
let lnum = line('.')
let line = getline(lnum)
if line =~ '^\s*$'
return
endif
if line =~ '^\s*\(=\+\).\+\1\s*$'
let level = vimwiki#count_first_sym(line)
let old = repeat('=', level)
let new = repeat('=', level - 1)
let chomp = line =~ '=\s'
let line = substitute(line, old, new, 'g')
if level == 1 && chomp
let line = substitute(line, '^\s', '', 'g')
let line = substitute(line, '\s$', '', 'g')
endif
call setline(lnum, line)
endif
endfunction
" }}}
" }}}

1099
autoload/vimwiki_html.vim Normal file

File diff suppressed because it is too large Load Diff

361
autoload/vimwiki_lst.vim Normal file
View File

@ -0,0 +1,361 @@
" Vimwiki autoload plugin file
" Todo lists related stuff here.
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
if exists("g:loaded_vimwiki_list_auto") || &cp
finish
endif
let g:loaded_vimwiki_lst_auto = 1
" Script variables {{{
let s:rx_li_box = '\[.\?\]'
" }}}
" Script functions {{{
" Get checkbox regexp
function! s:rx_li_symbol(rate) "{{{
let result = ''
if a:rate == 100
let result = g:vimwiki_listsyms[4]
elseif a:rate == 0
let result = g:vimwiki_listsyms[0]
elseif a:rate >= 67
let result = g:vimwiki_listsyms[3]
elseif a:rate >= 34
let result = g:vimwiki_listsyms[2]
else
let result = g:vimwiki_listsyms[1]
endif
return '\['.result.'\]'
endfunction "}}}
" Get regexp of the list item.
function! s:rx_list_item() "{{{
return '\('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)'
endfunction "}}}
" Get regexp of the list item with checkbox.
function! s:rx_cb_list_item() "{{{
" return s:rx_list_item().'\s*\zs\[.\?\]'
return s:rx_list_item().'\s*\zs\[.\?\]'
endfunction "}}}
" Get level of the list item.
function! s:get_level(lnum) "{{{
if VimwikiGet('syntax') == 'media'
let level = vimwiki#count_first_sym(getline(a:lnum))
else
let level = indent(a:lnum)
endif
return level
endfunction "}}}
" Get previous list item.
" Returns: line number or 0.
function! s:prev_list_item(lnum) "{{{
let c_lnum = a:lnum - 1
while c_lnum >= 1
let line = getline(c_lnum)
if line =~ s:rx_list_item()
return c_lnum
endif
if line =~ '^\s*$'
return 0
endif
let c_lnum -= 1
endwhile
return 0
endfunction "}}}
" Get next list item in the list.
" Returns: line number or 0.
function! s:next_list_item(lnum) "{{{
let c_lnum = a:lnum + 1
while c_lnum <= line('$')
let line = getline(c_lnum)
if line =~ s:rx_list_item()
return c_lnum
endif
if line =~ '^\s*$'
return 0
endif
let c_lnum += 1
endwhile
return 0
endfunction "}}}
" Find next list item in the buffer.
" Returns: line number or 0.
function! s:find_next_list_item(lnum) "{{{
let c_lnum = a:lnum + 1
while c_lnum <= line('$')
let line = getline(c_lnum)
if line =~ s:rx_list_item()
return c_lnum
endif
let c_lnum += 1
endwhile
return 0
endfunction "}}}
" Set state of the list item on line number "lnum" to [ ] or [x]
function! s:set_state(lnum, rate) "{{{
let line = getline(a:lnum)
let state = s:rx_li_symbol(a:rate)
let line = substitute(line, s:rx_li_box, state, '')
call setline(a:lnum, line)
endfunction "}}}
" Get state of the list item on line number "lnum"
function! s:get_state(lnum) "{{{
let state = 0
let line = getline(a:lnum)
let opt = matchstr(line, s:rx_cb_list_item())
if opt =~ s:rx_li_symbol(100)
let state = 100
elseif opt =~ s:rx_li_symbol(0)
let state = 0
elseif opt =~ s:rx_li_symbol(25)
let state = 25
elseif opt =~ s:rx_li_symbol(50)
let state = 50
elseif opt =~ s:rx_li_symbol(75)
let state = 75
endif
return state
endfunction "}}}
" Returns 1 if there is checkbox on a list item, 0 otherwise.
function! s:is_cb_list_item(lnum) "{{{
return getline(a:lnum) =~ s:rx_cb_list_item()
endfunction "}}}
" Returns start line number of list item, 0 if it is not a list.
function! s:is_list_item(lnum) "{{{
let c_lnum = a:lnum
while c_lnum >= 1
let line = getline(c_lnum)
if line =~ s:rx_list_item()
return c_lnum
endif
if line =~ '^\s*$'
return 0
endif
if indent(c_lnum) > indent(a:lnum)
return 0
endif
let c_lnum -= 1
endwhile
return 0
endfunction "}}}
" Returns char column of checkbox. Used in parent/child checks.
function! s:get_li_pos(lnum) "{{{
return stridx(getline(a:lnum), '[')
endfunction "}}}
" Returns list of line numbers of parent and all its child items.
function! s:get_child_items(lnum) "{{{
let result = []
let lnum = a:lnum
let p_pos = s:get_level(lnum)
" add parent
call add(result, lnum)
let lnum = s:next_list_item(lnum)
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) > p_pos
call add(result, lnum)
let lnum = s:next_list_item(lnum)
endwhile
return result
endfunction "}}}
" Returns list of line numbers of all items of the same level.
function! s:get_sibling_items(lnum) "{{{
let result = []
let lnum = a:lnum
let ind = s:get_level(lnum)
while s:get_level(lnum) >= ind &&
\ lnum != 0
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
call add(result, lnum)
endif
let lnum = s:next_list_item(lnum)
endwhile
let lnum = s:prev_list_item(a:lnum)
while s:get_level(lnum) >= ind &&
\ lnum != 0
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
call add(result, lnum)
endif
let lnum = s:prev_list_item(lnum)
endwhile
return result
endfunction "}}}
" Returns line number of the parent of lnum item
function! s:get_parent_item(lnum) "{{{
let lnum = a:lnum
let ind = s:get_level(lnum)
let lnum = s:prev_list_item(lnum)
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) >= ind
let lnum = s:prev_list_item(lnum)
endwhile
if s:is_cb_list_item(lnum)
return lnum
else
return a:lnum
endif
endfunction "}}}
" Creates checkbox in a list item.
function! s:create_cb_list_item(lnum) "{{{
let line = getline(a:lnum)
let m = matchstr(line, s:rx_list_item())
if m != ''
let li_content = substitute(strpart(line, len(m)), '^\s*', '', '')
let line = m.'[ ] '.li_content
call setline(a:lnum, line)
endif
endfunction "}}}
" Tells if all of the sibling list items are checked or not.
function! s:all_siblings_checked(lnum) "{{{
let result = 0
let cnt = 0
let siblings = s:get_sibling_items(a:lnum)
for lnum in siblings
let cnt += s:get_state(lnum)/100.0
endfor
let result = (cnt*100.0)/len(siblings)
return result
endfunction "}}}
" Creates checkbox on a list item if there is no one.
function! s:TLI_create_checkbox(lnum) "{{{
if a:lnum && !s:is_cb_list_item(a:lnum)
if g:vimwiki_auto_checkbox
call s:create_cb_list_item(a:lnum)
endif
return 1
endif
return 0
endfunction "}}}
" Switch state of the child list items.
function! s:TLI_switch_child_state(lnum) "{{{
let current_state = s:get_state(a:lnum)
if current_state == 100
let new_state = 0
else
let new_state = 100
endif
for lnum in s:get_child_items(a:lnum)
call s:set_state(lnum, new_state)
endfor
endfunction "}}}
" Switch state of the parent list items.
function! s:TLI_switch_parent_state(lnum) "{{{
let c_lnum = a:lnum
while s:is_cb_list_item(c_lnum)
let parent_lnum = s:get_parent_item(c_lnum)
if parent_lnum == c_lnum
break
endif
call s:set_state(parent_lnum, s:all_siblings_checked(c_lnum))
let c_lnum = parent_lnum
endwhile
endfunction "}}}
function! s:TLI_toggle(lnum) "{{{
if !s:TLI_create_checkbox(a:lnum)
call s:TLI_switch_child_state(a:lnum)
endif
call s:TLI_switch_parent_state(a:lnum)
endfunction "}}}
" Script functions }}}
" Toggle list item between [ ] and [X]
function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
let line1 = a:line1
let line2 = a:line2
if line1 != line2 && !s:is_list_item(line1)
let line1 = s:find_next_list_item(line1)
endif
let c_lnum = line1
while c_lnum != 0 && c_lnum <= line2
let li_lnum = s:is_list_item(c_lnum)
if li_lnum
let li_level = s:get_level(li_lnum)
if c_lnum == line1
let start_li_level = li_level
endif
if li_level <= start_li_level
call s:TLI_toggle(li_lnum)
let start_li_level = li_level
endif
endif
let c_lnum = s:find_next_list_item(c_lnum)
endwhile
endfunction "}}}
function! vimwiki_lst#insertCR() "{{{
" This function is heavily relies on proper 'set comments' option.
let cr = "\<CR>"
if getline('.') =~ s:rx_cb_list_item()
let cr .= '[ ] '
endif
return cr
endfunction "}}}
function! vimwiki_lst#insertOo(cmd) "{{{
" cmd should be 'o' or 'O'
let beg_lnum = foldclosed('.')
let end_lnum = foldclosedend('.')
if end_lnum != -1 && a:cmd ==# 'o'
let lnum = end_lnum
let line = getline(beg_lnum)
else
let line = getline('.')
let lnum = line('.')
endif
let res = ''
if line =~ s:rx_cb_list_item()
let res = matchstr(line, s:rx_list_item()).'[ ] '
elseif line =~ s:rx_list_item()
let res = matchstr(line, s:rx_list_item())
elseif &autoindent || &smartindent
let res = matchstr(line, '^\s*')
endif
if a:cmd ==# 'o'
call append(lnum, res)
call cursor(lnum + 1, col('$'))
else
call append(lnum - 1, res)
call cursor(lnum, col('$'))
endif
endfunction "}}}

1547
doc/vimwiki.txt Normal file

File diff suppressed because it is too large Load Diff

299
ftplugin/vimwiki.vim Normal file
View File

@ -0,0 +1,299 @@
" Vimwiki filetype plugin file
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1 " Don't load another plugin for this buffer
" UNDO list {{{
" Reset the following options to undo this plugin.
let b:undo_ftplugin = "setlocal wrap< linebreak< ".
\ "suffixesadd< isfname< comments< ".
\ "autowriteall< ".
\ "formatoptions< foldtext< ".
\ "foldmethod< foldexpr< commentstring< "
" UNDO }}}
" MISC STUFF {{{
setlocal wrap
setlocal linebreak
setlocal autowriteall
setlocal commentstring=<!--%s-->
" MISC }}}
" GOTO FILE: gf {{{
execute 'setlocal suffixesadd='.VimwikiGet('ext')
setlocal isfname-=[,]
" gf}}}
" Autocreate list items {{{
" for list items, and list items with checkboxes
if VimwikiGet('syntax') == 'default'
setl comments=b:*,b:#,b:-
setl formatlistpat=^\\s*[*#-]\\s*
else
setl comments=n:*,n:#
endif
setlocal formatoptions=tnro
inoremap <expr> <CR> vimwiki_lst#insertCR()
nnoremap o :call vimwiki_lst#insertOo('o')<CR>a
nnoremap O :call vimwiki_lst#insertOo('O')<CR>a
" COMMENTS }}}
" FOLDING for headers and list items using expr fold method. {{{
if g:vimwiki_folding == 1
setlocal fdm=expr
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
endif
function! VimwikiFoldLevel(lnum) "{{{
let line = getline(a:lnum)
" Header folding...
if line =~ g:vimwiki_rxHeader
let n = vimwiki#count_first_sym(line)
return '>'.n
endif
if g:vimwiki_fold_trailing_empty_lines == 0
if line =~ '^\s*$'
let nnline = getline(nextnonblank(a:lnum + 1))
if nnline =~ g:vimwiki_rxHeader
let n = vimwiki#count_first_sym(nnline)
return '<'.n
endif
endif
endif
" List item folding...
if g:vimwiki_fold_lists
let base_level = s:get_base_level(a:lnum)
let rx_list_item = '\('.
\ g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.
\ '\)'
if line =~ rx_list_item
let [nnum, nline] = s:find_forward(rx_list_item, a:lnum)
let level = s:get_li_level(a:lnum)
let leveln = s:get_li_level(nnum)
let adj = s:get_li_level(s:get_start_list(rx_list_item, a:lnum))
if leveln > level
return ">".(base_level+leveln-adj)
else
return (base_level+level-adj)
endif
else
" process multilined list items
let [pnum, pline] = s:find_backward(rx_list_item, a:lnum)
if pline =~ rx_list_item
if indent(a:lnum) > indent(pnum)
let level = s:get_li_level(pnum)
let adj = s:get_li_level(s:get_start_list(rx_list_item, pnum))
let [nnum, nline] = s:find_forward(rx_list_item, a:lnum)
if nline =~ rx_list_item
let leveln = s:get_li_level(nnum)
if leveln > level
return (base_level+leveln-adj)
endif
endif
return (base_level+level-adj)
endif
endif
endif
return base_level
endif
return -1
endfunction "}}}
function! s:get_base_level(lnum) "{{{
let lnum = a:lnum - 1
while lnum > 0
if getline(lnum) =~ g:vimwiki_rxHeader
return vimwiki#count_first_sym(getline(lnum))
endif
let lnum -= 1
endwhile
return 0
endfunction "}}}
function! s:find_forward(rx_item, lnum) "{{{
let lnum = a:lnum + 1
while lnum <= line('$')
let line = getline(lnum)
if line =~ a:rx_item
\ || line =~ '^\S'
\ || line =~ g:vimwiki_rxHeader
break
endif
let lnum += 1
endwhile
return [lnum, getline(lnum)]
endfunction "}}}
function! s:find_backward(rx_item, lnum) "{{{
let lnum = a:lnum - 1
while lnum > 1
let line = getline(lnum)
if line =~ a:rx_item
\ || line =~ '^\S'
break
endif
let lnum -= 1
endwhile
return [lnum, getline(lnum)]
endfunction "}}}
function! s:get_li_level(lnum) "{{{
if VimwikiGet('syntax') == 'media'
let level = vimwiki#count_first_sym(getline(a:lnum))
else
let level = (indent(a:lnum) / &sw)
endif
return level
endfunction "}}}
function! s:get_start_list(rx_item, lnum) "{{{
let lnum = a:lnum
while lnum >= 1
let line = getline(lnum)
if line !~ a:rx_item && line =~ '^\S'
return nextnonblank(lnum + 1)
endif
let lnum -= 1
endwhile
return 0
endfunction "}}}
function! VimwikiFoldText() "{{{
let line = substitute(getline(v:foldstart), '\t',
\ repeat(' ', &tabstop), 'g')
return line.' ['.(v:foldend - v:foldstart).']'
endfunction "}}}
" FOLDING }}}
" COMMANDS {{{
command! -buffer Vimwiki2HTML
\ call vimwiki_html#Wiki2HTML(expand(VimwikiGet('path_html')),
\ expand('%'))
command! -buffer VimwikiAll2HTML
\ call vimwiki_html#WikiAll2HTML(expand(VimwikiGet('path_html')))
command! -buffer VimwikiNextWord call vimwiki#WikiNextWord()
command! -buffer VimwikiPrevWord call vimwiki#WikiPrevWord()
command! -buffer VimwikiDeleteWord call vimwiki#WikiDeleteWord()
command! -buffer VimwikiRenameWord call vimwiki#WikiRenameWord()
command! -buffer VimwikiFollowWord call vimwiki#WikiFollowWord('nosplit')
command! -buffer VimwikiGoBackWord call vimwiki#WikiGoBackWord()
command! -buffer VimwikiSplitWord call vimwiki#WikiFollowWord('split')
command! -buffer VimwikiVSplitWord call vimwiki#WikiFollowWord('vsplit')
command! -buffer -range VimwikiToggleListItem call vimwiki_lst#ToggleListItem(<line1>, <line2>)
exe 'command! -buffer -nargs=* VimwikiSearch vimgrep <args> '.
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ')
exe 'command! -buffer -nargs=* VWS vimgrep <args> '.
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ')
" COMMANDS }}}
" KEYBINDINGS {{{
if g:vimwiki_use_mouse
nmap <buffer> <S-LeftMouse> <NOP>
nmap <buffer> <C-LeftMouse> <NOP>
noremap <silent><buffer> <2-LeftMouse> :VimwikiFollowWord<CR>
noremap <silent><buffer> <S-2-LeftMouse> <LeftMouse>:VimwikiSplitWord<CR>
noremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitWord<CR>
noremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackWord<CR>
endif
if !hasmapto('<Plug>VimwikiFollowWord')
nmap <silent><buffer> <CR> <Plug>VimwikiFollowWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiFollowWord :VimwikiFollowWord<CR>
if !hasmapto('<Plug>VimwikiSplitWord')
nmap <silent><buffer> <S-CR> <Plug>VimwikiSplitWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiSplitWord :VimwikiSplitWord<CR>
if !hasmapto('<Plug>VimwikiVSplitWord')
nmap <silent><buffer> <C-CR> <Plug>VimwikiVSplitWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiVSplitWord :VimwikiVSplitWord<CR>
if !hasmapto('<Plug>VimwikiGoBackWord')
nmap <silent><buffer> <BS> <Plug>VimwikiGoBackWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiGoBackWord :VimwikiGoBackWord<CR>
if !hasmapto('<Plug>VimwikiNextWord')
nmap <silent><buffer> <TAB> <Plug>VimwikiNextWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiNextWord :VimwikiNextWord<CR>
if !hasmapto('<Plug>VimwikiPrevWord')
nmap <silent><buffer> <S-TAB> <Plug>VimwikiPrevWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiPrevWord :VimwikiPrevWord<CR>
if !hasmapto('<Plug>VimwikiDeleteWord')
nmap <silent><buffer> <Leader>wd <Plug>VimwikiDeleteWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiDeleteWord :VimwikiDeleteWord<CR>
if !hasmapto('<Plug>VimwikiRenameWord')
nmap <silent><buffer> <Leader>wr <Plug>VimwikiRenameWord
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiRenameWord :VimwikiRenameWord<CR>
if !hasmapto('<Plug>VimwikiToggleListItem')
nmap <silent><buffer> <C-Space> <Plug>VimwikiToggleListItem
vmap <silent><buffer> <C-Space> <Plug>VimwikiToggleListItem
if has("unix")
nmap <silent><buffer> <C-@> <Plug>VimwikiToggleListItem
endif
endif
noremap <silent><script><buffer>
\ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR>
" Text objects {{{
omap <silent><buffer> ah :<C-U>call vimwiki#TO_header(0, 0)<CR>
vmap <silent><buffer> ah :<C-U>call vimwiki#TO_header(0, 1)<CR>
omap <silent><buffer> ih :<C-U>call vimwiki#TO_header(1, 0)<CR>
vmap <silent><buffer> ih :<C-U>call vimwiki#TO_header(1, 1)<CR>
nmap <silent><buffer> = :call vimwiki#AddHeaderLevel()<CR>
nmap <silent><buffer> - :call vimwiki#RemoveHeaderLevel()<CR>
" }}}
" KEYBINDINGS }}}

336
plugin/vimwiki.vim Normal file
View File

@ -0,0 +1,336 @@
" Vimwiki plugin file
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
" GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki
if exists("loaded_vimwiki") || &cp
finish
endif
let loaded_vimwiki = 1
let s:old_cpo = &cpo
set cpo&vim
" HELPER functions {{{
function! s:default(varname, value) "{{{
if !exists('g:vimwiki_'.a:varname)
let g:vimwiki_{a:varname} = a:value
endif
endfunction "}}}
function! Str_common_part(str1, str2)"{{{
let idx = 0
let minlen = min([len(a:str1), len(a:str2)])
while (idx < minlen) && (a:str1[idx] == a:str2[idx])
let idx = idx + 1
endwhile
return strpart(a:str1, 0, idx)
endfunction"}}}
function! s:chomp_slash(str)"{{{
return substitute(a:str, '[/\\]\+$', '', '')
endfunction"}}}
function! s:find_wiki(path) "{{{
let idx = 0
while idx < len(g:vimwiki_list)
let path = s:chomp_slash(expand(VimwikiGet('path', idx)))
if Str_common_part(path, a:path) == path
return idx
endif
let idx += 1
endwhile
return -1
endfunction "}}}
function! s:setup_buffer_leave()"{{{
if &filetype == 'vimwiki' && !exists("b:vimwiki_idx")
let b:vimwiki_idx = g:vimwiki_current_idx
endif
endfunction"}}}
function! s:setup_buffer_enter() "{{{
if exists("b:vimwiki_idx")
let g:vimwiki_current_idx = b:vimwiki_idx
else
" Find what wiki current buffer belongs to.
" If wiki does not exist in g:vimwiki_list -- add new wiki there with
" buffer's path and ext.
" Else set g:vimwiki_current_idx to that wiki index.
let path = expand('%:p:h')
let ext = '.'.expand('%:e')
let idx = s:find_wiki(path)
" The buffer's file is not in the path and user do not want his wiki
" extension to be global -- do not add new wiki.
if idx == -1 && g:vimwiki_global_ext == 0
return
endif
if idx == -1
call add(g:vimwiki_list, {'path': path, 'ext': ext})
let g:vimwiki_current_idx = len(g:vimwiki_list) - 1
else
let g:vimwiki_current_idx = idx
endif
let b:vimwiki_idx = g:vimwiki_current_idx
endif
call s:setup_colors()
if &filetype != 'vimwiki'
setlocal ft=vimwiki
else
setlocal syntax=vimwiki
endif
" Settings foldmethod, foldexpr and foldtext are local to window. Thus in a
" new tab with the same buffer folding is reset to vim defaults. So we
" insist vimwiki folding here.
" TODO: remove the same from ftplugin.
if g:vimwiki_folding == 1 && &fdm != 'expr'
setlocal fdm=expr
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
endif
endfunction "}}}
function! s:setup_colors()"{{{
if g:vimwiki_hl_headers == 0
return
endif
if &background == 'light'
hi def VimwikiHeader1 guibg=bg guifg=#aa5858 gui=bold ctermfg=DarkRed
hi def VimwikiHeader2 guibg=bg guifg=#309010 gui=bold ctermfg=DarkGreen
hi def VimwikiHeader3 guibg=bg guifg=#1030a0 gui=bold ctermfg=DarkBlue
hi def VimwikiHeader4 guibg=bg guifg=#103040 gui=bold ctermfg=Black
hi def VimwikiHeader5 guibg=bg guifg=#001020 gui=bold ctermfg=Black
hi def VimwikiHeader6 guibg=bg guifg=#000000 gui=bold ctermfg=Black
else
hi def VimwikiHeader1 guibg=bg guifg=#e08090 gui=bold ctermfg=Red
hi def VimwikiHeader2 guibg=bg guifg=#80e090 gui=bold ctermfg=Green
hi def VimwikiHeader3 guibg=bg guifg=#6090e0 gui=bold ctermfg=Blue
hi def VimwikiHeader4 guibg=bg guifg=#c0c0f0 gui=bold ctermfg=White
hi def VimwikiHeader5 guibg=bg guifg=#e0e0f0 gui=bold ctermfg=White
hi def VimwikiHeader6 guibg=bg guifg=#f0f0f0 gui=bold ctermfg=White
endif
endfunction"}}}
" OPTION get/set functions {{{
" return value of option for current wiki or if second parameter exists for
" wiki with a given index.
function! VimwikiGet(option, ...) "{{{
if a:0 == 0
let idx = g:vimwiki_current_idx
else
let idx = a:1
endif
if !has_key(g:vimwiki_list[idx], a:option) &&
\ has_key(s:vimwiki_defaults, a:option)
if a:option == 'path_html'
let g:vimwiki_list[idx][a:option] =
\VimwikiGet('path', idx)[:-2].'_html/'
else
let g:vimwiki_list[idx][a:option] =
\s:vimwiki_defaults[a:option]
endif
endif
" if path's ending is not a / or \
" then add it
if a:option == 'path' || a:option == 'path_html'
let p = g:vimwiki_list[idx][a:option]
" resolve doesn't work quite right with symlinks ended with / or \
let p = substitute(p, '[/\\]\+$', '', '')
let p = resolve(expand(p))
let g:vimwiki_list[idx][a:option] = p.'/'
endif
return g:vimwiki_list[idx][a:option]
endfunction "}}}
" set option for current wiki or if third parameter exists for
" wiki with a given index.
function! VimwikiSet(option, value, ...) "{{{
if a:0 == 0
let idx = g:vimwiki_current_idx
else
let idx = a:1
endif
let g:vimwiki_list[idx][a:option] = a:value
endfunction "}}}
" }}}
" }}}
" CALLBACK function "{{{
" User can redefine it.
if !exists("*VimwikiWeblinkHandler") "{{{
function VimwikiWeblinkHandler(weblink)
for browser in g:vimwiki_browsers
if executable(browser)
if has("win32")
execute '!start "'.browser.'" ' . a:weblink
else
execute '!'.browser.' ' . a:weblink
endif
return
endif
endfor
endfunction
endif "}}}
" CALLBACK }}}
" DEFAULT wiki {{{
let s:vimwiki_defaults = {}
let s:vimwiki_defaults.path = '~/vimwiki/'
let s:vimwiki_defaults.path_html = '~/vimwiki_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 = 1
let s:vimwiki_defaults.syntax = 'default'
let s:vimwiki_defaults.gohome = 'split'
let s:vimwiki_defaults.html_header = ''
let s:vimwiki_defaults.html_footer = ''
let s:vimwiki_defaults.nested_syntaxes = {}
"}}}
" DEFAULT options {{{
call s:default('list', [s:vimwiki_defaults])
if &encoding == 'utf-8'
call s:default('upper', 'A-Z\u0410-\u042f')
call s:default('lower', 'a-z\u0430-\u044f')
else
call s:default('upper', 'A-Z')
call s:default('lower', 'a-z')
endif
call s:default('other', '0-9')
call s:default('stripsym', '_')
call s:default('badsyms', '')
call s:default('auto_checkbox', 1)
call s:default('use_mouse', 0)
call s:default('folding', 0)
call s:default('fold_trailing_empty_lines', 0)
call s:default('fold_lists', 0)
call s:default('menu', 'Vimwiki')
call s:default('global_ext', 1)
call s:default('hl_headers', 0)
call s:default('hl_cb_checked', 0)
call s:default('camel_case', 1)
call s:default('list_ignore_newline', 1)
call s:default('listsyms', ' .oOX')
if has("win32")
call s:default('browsers',
\ [
\ expand('~').'\Local Settings\Application Data\Google\Chrome\Application\chrome.exe',
\ 'C:\Program Files\Opera\opera.exe',
\ 'C:\Program Files\Mozilla Firefox\firefox.exe',
\ 'C:\Program Files\Internet Explorer\iexplore.exe',
\ ])
else
call s:default('browsers',
\ [
\ 'opera',
\ 'firefox',
\ 'konqueror',
\ ])
endif
call s:default('current_idx', 0)
let upp = g:vimwiki_upper
let low = g:vimwiki_lower
let oth = g:vimwiki_other
let nup = low.oth
let nlo = upp.oth
let any = upp.nup
let g:vimwiki_word1 = '\C\<['.upp.']['.nlo.']*['.
\ low.']['.nup.']*['.upp.']['.any.']*\>'
let g:vimwiki_word2 = '\[\[[^\]]\+\]\]'
let g:vimwiki_word3 = '\[\[[^\]]\+\]\[[^\]]\+\]\]'
if g:vimwiki_camel_case
let g:vimwiki_rxWikiWord = g:vimwiki_word1.'\|'.g:vimwiki_word2.'\|'.g:vimwiki_word3
else
let g:vimwiki_rxWikiWord = g:vimwiki_word2.'\|'.g:vimwiki_word3
endif
let g:vimwiki_rxWeblink = '\%("[^"(]\+\((\([^)]\+\))\)\?":\)\?'.
\'\%(https\?\|ftp\|gopher\|telnet\|file\|notes\|ms-help\):'.
\'\%(\%(\%(//\)\|\%(\\\\\)\)\+[A-Za-z0-9:#@%/;,$~()_?+=.&\\\-]*\)'
"}}}
" FILETYPE setup for all known wiki extensions {{{
" Getting all extensions that different wikies could have
let extensions = {}
for wiki in g:vimwiki_list
if has_key(wiki, 'ext')
let extensions[wiki.ext] = 1
else
let extensions['.wiki'] = 1
endif
endfor
augroup filetypedetect
" clear FlexWiki's stuff
au! * *.wiki
augroup end
augroup vimwiki
autocmd!
for ext in keys(extensions)
execute 'autocmd BufEnter *'.ext.' call s:setup_buffer_enter()'
execute 'autocmd BufLeave,BufHidden *'.ext.' call s:setup_buffer_leave()'
" ColorScheme could have or could have not a VimwikiHeader1..VimwikiHeader6
" highlight groups. We need to refresh syntax after colorscheme change.
execute 'autocmd ColorScheme *'.ext.' call s:setup_colors() | set syntax=vimwiki'
endfor
augroup END
"}}}
" COMMANDS {{{
command! VimwikiUISelect call vimwiki#WikiUISelect()
command! -count VimwikiGoHome
\ call vimwiki#WikiGoHome(v:count1)
command! -count VimwikiTabGoHome tabedit <bar>
\ call vimwiki#WikiGoHome(v:count1)
"}}}
" MAPPINGS {{{
if !hasmapto('<Plug>VimwikiGoHome')
map <silent><unique> <Leader>ww <Plug>VimwikiGoHome
endif
noremap <unique><script> <Plug>VimwikiGoHome :VimwikiGoHome<CR>
if !hasmapto('<Plug>VimwikiTabGoHome')
map <silent><unique> <Leader>wt <Plug>VimwikiTabGoHome
endif
noremap <unique><script> <Plug>VimwikiTabGoHome :VimwikiTabGoHome<CR>
if !hasmapto('<Plug>VimwikiUISelect')
map <silent><unique> <Leader>ws <Plug>VimwikiUISelect
endif
noremap <unique><script> <Plug>VimwikiUISelect :VimwikiUISelect<CR>
"}}}
" MENU {{{
function! s:build_menu(path)
let idx = 0
while idx < len(g:vimwiki_list)
execute 'menu '.a:path.'.'.VimwikiGet('path', idx).
\ ' :call vimwiki#WikiGoHome('.(idx + 1).')<CR>'
let idx += 1
endwhile
endfunction
if !empty(g:vimwiki_menu)
call s:build_menu(g:vimwiki_menu)
endif
" }}}
let &cpo = s:old_cpo

141
syntax/vimwiki.vim Normal file
View File

@ -0,0 +1,141 @@
" Vimwiki syntax file
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
" vim:tw=79:
" Quit if syntax file is already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
"" use max highlighting - could be quite slow if there are too many wikifiles
if VimwikiGet('maxhi')
" Every WikiWord is nonexistent
if g:vimwiki_camel_case
execute 'syntax match VimwikiNoExistsWord /\%(^\|[^!]\)\@<='.g:vimwiki_word1.'/'
endif
execute 'syntax match VimwikiNoExistsWord /'.g:vimwiki_word2.'/'
execute 'syntax match VimwikiNoExistsWord /'.g:vimwiki_word3.'/'
" till we find them in vimwiki's path
call vimwiki#WikiHighlightWords()
else
" A WikiWord (unqualifiedWikiName)
execute 'syntax match VimwikiWord /\%(^\|[^!]\)\@<=\<'.g:vimwiki_word1.'\>/'
" A [[bracketed wiki word]]
execute 'syntax match VimwikiWord /'.g:vimwiki_word2.'/'
endif
execute 'syntax match VimwikiLink `'.g:vimwiki_rxWeblink.'`'
" Emoticons
syntax match VimwikiEmoticons /\%((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/
let g:vimwiki_rxTodo = '\C\%(TODO:\|DONE:\|FIXME:\|FIXED:\|XXX:\)'
execute 'syntax match VimwikiTodo /'. g:vimwiki_rxTodo .'/'
" Load concrete Wiki syntax
execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'.vim'
" Tables
execute 'syntax match VimwikiTable /'.g:vimwiki_rxTable.'/'
" List items
execute 'syntax match VimwikiList /'.g:vimwiki_rxListBullet.'/'
execute 'syntax match VimwikiList /'.g:vimwiki_rxListNumber.'/'
execute 'syntax match VimwikiList /'.g:vimwiki_rxListDefine.'/'
execute 'syntax match VimwikiBold /'.g:vimwiki_rxBold.'/'
execute 'syntax match VimwikiItalic /'.g:vimwiki_rxItalic.'/'
execute 'syntax match VimwikiBoldItalic /'.g:vimwiki_rxBoldItalic.'/'
execute 'syntax match VimwikiItalicBold /'.g:vimwiki_rxItalicBold.'/'
execute 'syntax match VimwikiDelText /'.g:vimwiki_rxDelText.'/'
execute 'syntax match VimwikiSuperScript /'.g:vimwiki_rxSuperScript.'/'
execute 'syntax match VimwikiSubScript /'.g:vimwiki_rxSubScript.'/'
execute 'syntax match VimwikiCode /'.g:vimwiki_rxCode.'/'
" <hr> horizontal rule
execute 'syntax match VimwikiHR /'.g:vimwiki_rxHR.'/'
execute 'syntax region VimwikiPre start=/'.g:vimwiki_rxPreStart.
\ '/ end=/'.g:vimwiki_rxPreEnd.'/ contains=VimwikiComment'
" List item checkbox
syntax match VimwikiCheckBox /\[.\?\]/
if g:vimwiki_hl_cb_checked
execute 'syntax match VimwikiCheckBoxDone /'.
\ g:vimwiki_rxListBullet.'\s*\['.g:vimwiki_listsyms[4].'\].*$/'
execute 'syntax match VimwikiCheckBoxDone /'.
\ g:vimwiki_rxListNumber.'\s*\['.g:vimwiki_listsyms[4].'\].*$/'
endif
syntax region VimwikiComment start='<!--' end='-->'
if !vimwiki#hl_exists("VimwikiHeader1")
execute 'syntax match VimwikiHeader /'.g:vimwiki_rxHeader.'/'
else
" Header levels, 1-6
execute 'syntax match VimwikiHeader1 /'.g:vimwiki_rxH1.'/'
execute 'syntax match VimwikiHeader2 /'.g:vimwiki_rxH2.'/'
execute 'syntax match VimwikiHeader3 /'.g:vimwiki_rxH3.'/'
execute 'syntax match VimwikiHeader4 /'.g:vimwiki_rxH4.'/'
execute 'syntax match VimwikiHeader5 /'.g:vimwiki_rxH5.'/'
execute 'syntax match VimwikiHeader6 /'.g:vimwiki_rxH6.'/'
endif
" group names "{{{
if !vimwiki#hl_exists("VimwikiHeader1")
hi def link VimwikiHeader Title
else
hi def link VimwikiHeader1 Title
hi def link VimwikiHeader2 Title
hi def link VimwikiHeader3 Title
hi def link VimwikiHeader4 Title
hi def link VimwikiHeader5 Title
hi def link VimwikiHeader6 Title
endif
hi def VimwikiBold term=bold cterm=bold gui=bold
hi def VimwikiItalic term=italic cterm=italic gui=italic
hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic
hi def link VimwikiItalicBold VimwikiBoldItalic
hi def link VimwikiCode PreProc
hi def link VimwikiWord Underlined
hi def link VimwikiNoExistsWord Error
hi def link VimwikiPre SpecialComment
hi def link VimwikiLink Underlined
hi def link VimwikiList Function
hi def link VimwikiCheckBox VimwikiList
hi def link VimwikiCheckBoxDone Comment
hi def link VimwikiTable PreProc
hi def link VimwikiEmoticons Character
hi def link VimwikiDelText Constant
hi def link VimwikiSuperScript Number
hi def link VimwikiSubScript Number
hi def link VimwikiTodo Todo
hi def link VimwikiComment Comment
"}}}
let b:current_syntax="vimwiki"
" EMBEDDED syntax setup "{{{
let nested = VimwikiGet('nested_syntaxes')
if !empty(nested)
for [hl_syntax, vim_syntax] in items(nested)
call vimwiki#nested_syntax(vim_syntax,
\ '^{{{\%(.*[[:blank:][:punct:]]\)\?'.
\ hl_syntax.'\%([[:blank:][:punct:]].*\)\?',
\ '^}}}', 'VimwikiPre')
endfor
endif
"}}}

View File

@ -0,0 +1,76 @@
" Vimwiki syntax file
" Default syntax
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
" vim:tw=78:
" text: *strong*
" let g:vimwiki_rxBold = '\*[^*]\+\*'
let g:vimwiki_rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`]\)'.
\'\*'.
\'\%([[:punct:]]\|\s\|$\)\@='
" text: _emphasis_
" let g:vimwiki_rxItalic = '_[^_]\+_'
let g:vimwiki_rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`]\)'.
\'_'.
\'\%([[:punct:]]\|\s\|$\)\@='
" text: *_bold italic_* or _*italic bold*_
let g:vimwiki_rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*_'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`]\)'.
\'_\*'.
\'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_\*'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`]\)'.
\'\*_'.
\'\%([[:punct:]]\|\s\|$\)\@='
" text: `code`
let g:vimwiki_rxCode = '`[^`]\+`'
" text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~`]\+\~\~'
" text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^`]\+\^'
" text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,`]\+,,'
" Header levels, 1-6
let g:vimwiki_rxH1 = '^\s*=\{1}[^=]\+.*[^=]\+=\{1}\s*$'
let g:vimwiki_rxH2 = '^\s*=\{2}[^=]\+.*[^=]\+=\{2}\s*$'
let g:vimwiki_rxH3 = '^\s*=\{3}[^=]\+.*[^=]\+=\{3}\s*$'
let g:vimwiki_rxH4 = '^\s*=\{4}[^=]\+.*[^=]\+=\{4}\s*$'
let g:vimwiki_rxH5 = '^\s*=\{5}[^=]\+.*[^=]\+=\{5}\s*$'
let g:vimwiki_rxH6 = '^\s*=\{6}[^=]\+.*[^=]\+=\{6}\s*$'
let g:vimwiki_rxHeader = '\%('.g:vimwiki_rxH1.'\)\|'.
\ '\%('.g:vimwiki_rxH2.'\)\|'.
\ '\%('.g:vimwiki_rxH3.'\)\|'.
\ '\%('.g:vimwiki_rxH4.'\)\|'.
\ '\%('.g:vimwiki_rxH5.'\)\|'.
\ '\%('.g:vimwiki_rxH6.'\)'
" <hr>, horizontal rule
let g:vimwiki_rxHR = '^----.*$'
" Tables. Each line starts and ends with '||'; each cell is separated by '||'
let g:vimwiki_rxTable = '||'
" List items start with optional whitespace(s) then '* ' or '# '
let g:vimwiki_rxListBullet = '^\s*\%(\*\|-\)\s'
let g:vimwiki_rxListNumber = '^\s*#\s'
let g:vimwiki_rxListDefine = '::\(\s\|$\)'
" Preformatted text
let g:vimwiki_rxPreStart = '{{{'
let g:vimwiki_rxPreEnd = '}}}'

58
syntax/vimwiki_media.vim Normal file
View File

@ -0,0 +1,58 @@
" Vimwiki syntax file
" MediaWiki syntax
" Author: Maxim Kim <habamax@gmail.com>
" Home: http://code.google.com/p/vimwiki/
" vim:tw=78:
" text: '''strong'''
let g:vimwiki_rxBold = "'''[^']\\+'''"
" text: ''emphasis''
let g:vimwiki_rxItalic = "''[^']\\+''"
" text: '''''strong italic'''''
let g:vimwiki_rxBoldItalic = "'''''[^']\\+'''''"
let g:vimwiki_rxItalicBold = g:vimwiki_rxBoldItalic
" text: `code`
let g:vimwiki_rxCode = '`[^`]\+`'
" text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~]\+\~\~'
" text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^]\+\^'
" text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,]\+,,'
" Header levels, 1-6
let g:vimwiki_rxH1 = '^\s*=\{1}[^=]\+.*[^=]\+=\{1}\s*$'
let g:vimwiki_rxH2 = '^\s*=\{2}[^=]\+.*[^=]\+=\{2}\s*$'
let g:vimwiki_rxH3 = '^\s*=\{3}[^=]\+.*[^=]\+=\{3}\s*$'
let g:vimwiki_rxH4 = '^\s*=\{4}[^=]\+.*[^=]\+=\{4}\s*$'
let g:vimwiki_rxH5 = '^\s*=\{5}[^=]\+.*[^=]\+=\{5}\s*$'
let g:vimwiki_rxH6 = '^\s*=\{6}[^=]\+.*[^=]\+=\{6}\s*$'
let g:vimwiki_rxHeader = '\%('.g:vimwiki_rxH1.'\)\|'.
\ '\%('.g:vimwiki_rxH2.'\)\|'.
\ '\%('.g:vimwiki_rxH3.'\)\|'.
\ '\%('.g:vimwiki_rxH4.'\)\|'.
\ '\%('.g:vimwiki_rxH5.'\)\|'.
\ '\%('.g:vimwiki_rxH6.'\)'
" <hr>, horizontal rule
let g:vimwiki_rxHR = '^----.*$'
" Tables. Each line starts and ends with '||'; each cell is separated by '||'
let g:vimwiki_rxTable = '||'
" Bulleted list items start with whitespace(s), then '*'
" highlight only bullets and digits.
let g:vimwiki_rxListBullet = '^\s*\*\+\([^*]*$\)\@='
let g:vimwiki_rxListNumber = '^\s*#\+'
let g:vimwiki_rxListDefine = '^\%(;\|:\)\s'
" Preformatted text
let g:vimwiki_rxPreStart = '<pre>'
let g:vimwiki_rxPreEnd = '<\/pre>'

File diff suppressed because it is too large Load Diff