" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki filetype plugin file " Author: Maxim Kim " 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 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 if g:vimwiki_conceallevel && exists("+conceallevel") let &l:conceallevel = g:vimwiki_conceallevel endif " GOTO FILE: gf {{{ execute 'setlocal suffixesadd='.VimwikiGet('ext') setlocal isfname-=[,] " gf}}} setlocal tags+=./.tags " MISC }}} " COMPLETION {{{ function! Complete_wikifiles(findstart, base) if a:findstart == 1 let column = col('.')-2 let line = getline('.')[:column] let startoflink = match(line, '\[\[\zs[^\\[\]]*$') if startoflink != -1 let s:line_context = '[' return startoflink endif if VimwikiGet('syntax') == 'markdown' let startofinlinelink = match(line, '\[.*\](\zs[^)]*$') if startofinlinelink != -1 let s:line_context = '[' return startofinlinelink endif endif let startoftag = match(line, ':\zs[^:[:space:]]*$') if startoftag != -1 let s:line_context = ':' return startoftag endif let s:line_context = '' return -1 else " 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 " solution, because calling col('.') here returns garbage. if s:line_context == '' return [] elseif s:line_context == ':' " Tags completion let metadata = vimwiki#base#load_tags_metadata() let tags = vimwiki#base#get_tags(metadata) if a:base != '' call filter(tags, \ "v:val[:" . (len(a:base)-1) . "] == '" . substitute(a:base, "'", "''", '') . "'" ) endif return tags elseif a:base !~ '#' " we look for wiki files if a:base =~# '^wiki\d:' let wikinumber = eval(matchstr(a:base, '^wiki\zs\d')) if wikinumber >= len(g:vimwiki_list) return [] endif let prefix = matchstr(a:base, '^wiki\d:\zs.*') let scheme = matchstr(a:base, '^wiki\d:\ze') elseif a:base =~# '^diary:' let wikinumber = -1 let prefix = matchstr(a:base, '^diary:\zs.*') let scheme = matchstr(a:base, '^diary:\ze') else " current wiki let wikinumber = g:vimwiki_current_idx let prefix = a:base let scheme = '' endif let links = vimwiki#base#get_wikilinks(wikinumber) let result = [] for wikifile in links if wikifile =~ '^'.vimwiki#u#escape(prefix) call add(result, scheme . wikifile) endif endfor return result else " we look for anchors in the given wikifile let segments = split(a:base, '#', 1) let given_wikifile = segments[0]=='' ? expand('%:t:r') : segments[0] let link_infos = vimwiki#base#resolve_scheme(given_wikifile.'#', 0, 1) let wikifile = link_infos[6] let syntax = VimwikiGet('syntax', link_infos[0]) let anchors = vimwiki#base#get_anchors(wikifile, syntax) let filtered_anchors = [] let given_anchor = join(segments[1:], '#') for anchor in anchors if anchor =~# '^'.vimwiki#u#escape(given_anchor) call add(filtered_anchors, segments[0].'#'.anchor) endif endfor return filtered_anchors endif endif endfunction setlocal omnifunc=Complete_wikifiles " COMPLETION }}} " LIST STUFF {{{ " settings necessary for the automatic formatting of lists setlocal autoindent setlocal nosmartindent setlocal nocindent setlocal comments="" setlocal formatoptions-=c setlocal formatoptions-=r setlocal formatoptions-=o setlocal formatoptions-=2 setlocal formatoptions+=n "Create 'formatlistpat' let &formatlistpat = g:vimwiki_rxListItem if !empty(&langmap) " Valid only if langmap is a comma separated pairs of chars let s:l_o = matchstr(&langmap, '\C,\zs.\zeo,') if s:l_o exe 'nnoremap '.s:l_o.' :call vimwiki#lst#kbd_o()a' endif let s:l_O = matchstr(&langmap, '\C,\zs.\zeO,') if s:l_O exe 'nnoremap '.s:l_O.' :call vimwiki#lst#kbd_O()a' endif endif " LIST STUFF }}} " FOLDING {{{ " Folding list items {{{ function! VimwikiFoldListLevel(lnum) "{{{ return vimwiki#lst#fold_level(a:lnum) endfunction "}}} " Folding list items }}} " Folding sections and code blocks {{{ function! VimwikiFoldLevel(lnum) "{{{ let line = getline(a:lnum) " Header/section folding... if line =~ g:vimwiki_rxHeader return '>'.vimwiki#u#count_first_sym(line) " Code block folding... elseif line =~ '^\s*'.g:vimwiki_rxPreStart return 'a1' elseif line =~ '^\s*'.g:vimwiki_rxPreEnd.'\s*$' return 's1' else return "=" endif endfunction "}}} " Constants used by VimwikiFoldText {{{ " use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space let s:ellipsis = (&enc ==? 'utf-8') ? "\u2026" : "..." let s:ell_len = strlen(s:ellipsis) let s:newline = (&enc ==? 'utf-8') ? "\u21b2 " : " " let s:tolerance = 5 " }}} function! s:shorten_text_simple(text, len) "{{{ unused let spare_len = a:len - len(a:text) return (spare_len>=0) ? [a:text,spare_len] : [a:text[0:a:len].s:ellipsis, -1] endfunction "}}} " 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" " (so that -s:tolerance <= spare <= s:tolerance, "string" ends with s:ellipsis) function! s:shorten_text(text, len) "{{{ returns [string, spare] let spare_len = a:len - strlen(a:text) if (spare_len + s:tolerance >= 0) return [a:text, spare_len] endif " try to break on a space; assumes a:len-s:ell_len >= s:tolerance let newlen = a:len - s:ell_len let idx = strridx(a:text, ' ', newlen + s:tolerance) let break_idx = (idx + s:tolerance >= newlen) ? idx : newlen return [a:text[0:break_idx].s:ellipsis, newlen - break_idx] endfunction "}}} function! VimwikiFoldText() "{{{ let line = getline(v:foldstart) let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '') let fold_len = v:foldend - v:foldstart + 1 let len_text = ' ['.fold_len.'] ' if line !~ '^\s*'.g:vimwiki_rxPreStart let [main_text, spare_len] = s:shorten_text(main_text, 50) return main_text.len_text else " fold-text for code blocks: use one or two of the starting lines let [main_text, spare_len] = s:shorten_text(main_text, 24) let line1 = substitute(getline(v:foldstart+1), '^\s*', ' ', '') let [content_text, spare_len] = s:shorten_text(line1, spare_len+20) if spare_len > s:tolerance && fold_len > 3 let line2 = substitute(getline(v:foldstart+2), '^\s*', s:newline, '') let [more_text, spare_len] = s:shorten_text(line2, spare_len+12) let content_text .= more_text endif return main_text.len_text.content_text endif endfunction "}}} " Folding sections and code blocks }}} " FOLDING }}} " COMMANDS {{{ command! -buffer Vimwiki2HTML \ if filewritable(expand('%')) | silent noautocmd w | endif \ \ let res = vimwiki#html#Wiki2HTML(expand(VimwikiGet('path_html')), \ expand('%')) \ \ if res != '' | echo 'Vimwiki: HTML conversion is done, output: '.expand(VimwikiGet('path_html')) | endif command! -buffer Vimwiki2HTMLBrowse \ if filewritable(expand('%')) | silent noautocmd w | endif \ \ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML( \ expand(VimwikiGet('path_html')), \ expand('%'))) command! -buffer VimwikiAll2HTML \ call vimwiki#html#WikiAll2HTML(expand(VimwikiGet('path_html'))) command! -buffer VimwikiTOC call vimwiki#base#table_of_contents(1) command! -buffer VimwikiNextLink call vimwiki#base#find_next_link() command! -buffer VimwikiPrevLink call vimwiki#base#find_prev_link() command! -buffer VimwikiDeleteLink call vimwiki#base#delete_link() command! -buffer VimwikiRenameLink call vimwiki#base#rename_link() command! -buffer VimwikiFollowLink call vimwiki#base#follow_link('nosplit') command! -buffer VimwikiGoBackLink call vimwiki#base#go_back_link() command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('split') command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit') command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link() command! -buffer VimwikiTabnewLink call vimwiki#base#follow_link('tabnew') command! -buffer VimwikiGenerateLinks call vimwiki#base#generate_links() command! -buffer -nargs=0 VimwikiBacklinks call vimwiki#base#backlinks() command! -buffer -nargs=0 VWB call vimwiki#base#backlinks() exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') exe 'command! -buffer -nargs=* VWS lvimgrep '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped \ VimwikiGoto call vimwiki#base#goto() command! -buffer VimwikiCheckLinks call vimwiki#base#check_links() " list commands command! -buffer -nargs=+ VimwikiReturn call CR() command! -buffer -range -nargs=1 VimwikiChangeSymbolTo call vimwiki#lst#change_marker(, , , 'n') command! -buffer -range -nargs=1 VimwikiListChangeSymbolI call vimwiki#lst#change_marker(, , , 'i') command! -buffer -nargs=1 VimwikiChangeSymbolInListTo call vimwiki#lst#change_marker_in_list() command! -buffer -range VimwikiToggleListItem call vimwiki#lst#toggle_cb(, ) command! -buffer -range -nargs=+ VimwikiListChangeLvl call vimwiki#lst#change_level(, , ) command! -buffer -range VimwikiRemoveSingleCB call vimwiki#lst#remove_cb(, ) command! -buffer VimwikiRemoveCBInList call vimwiki#lst#remove_cb_in_list() command! -buffer VimwikiRenumberList call vimwiki#lst#adjust_numbered_list() command! -buffer VimwikiRenumberAllLists call vimwiki#lst#adjust_whole_buffer() command! -buffer VimwikiListToggle call vimwiki#lst#toggle_list_item() " table commands command! -buffer -nargs=* VimwikiTable call vimwiki#tbl#create() command! -buffer VimwikiTableAlignQ call vimwiki#tbl#align_or_cmd('gqq') command! -buffer VimwikiTableAlignW call vimwiki#tbl#align_or_cmd('gww') command! -buffer VimwikiTableMoveColumnLeft call vimwiki#tbl#move_column_left() command! -buffer VimwikiTableMoveColumnRight call vimwiki#tbl#move_column_right() " diary commands command! -buffer VimwikiDiaryNextDay call vimwiki#diary#goto_next_day() command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day() " tags commands command! -buffer VimwikiRebuildTags call vimwiki#base#update_tags(1) command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_tags \ VimwikiSearchTags VimwikiSearch /::/ command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_tags \ VimwikiGenerateTags call vimwiki#base#generate_tags() " COMMANDS }}} " KEYBINDINGS {{{ if g:vimwiki_use_mouse nmap nmap nnoremap <2-LeftMouse> :call vimwiki#base#follow_link("nosplit", "\2-LeftMouse>") nnoremap :VimwikiSplitLink nnoremap :VimwikiVSplitLink nnoremap :VimwikiGoBackLink endif if !hasmapto('Vimwiki2HTML') exe 'nmap '.g:vimwiki_map_prefix.'h Vimwiki2HTML' endif nnoremap