" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 " Vimwiki filetype plugin file " Home: https://github.com/vimwiki/vimwiki/ if exists("b:did_ftplugin") finish endif let b:did_ftplugin = 1 " Don't load another plugin for this buffer setlocal commentstring=%%%s if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel") let &l:conceallevel = vimwiki#vars#get_global('conceallevel') endif " This is for GOTO FILE: gf execute 'setlocal suffixesadd='.vimwiki#vars#get_wikilocal('ext') setlocal isfname-=[,] exe "setlocal tags+=" . escape(vimwiki#tags#metadata_file_path(), ' \|"') 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 vimwiki#vars#get_wikilocal('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 tags = vimwiki#tags#get_tags() 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 =~# '\m^wiki\d\+:' let wikinumber = eval(matchstr(a:base, '\m^wiki\zs\d\+')) if wikinumber >= vimwiki#vars#number_of_wikis() return [] endif let prefix = matchstr(a:base, '\m^wiki\d\+:\zs.*') let scheme = matchstr(a:base, '\m^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 = vimwiki#vars#get_bufferlocal('wiki_nr') let prefix = a:base let scheme = '' endif let links = vimwiki#base#get_wikilinks(wikinumber, 1) 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_link(given_wikifile.'#') let wikifile = link_infos.filename let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index) 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 " 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 let &formatlistpat = vimwiki#vars#get_syntaxlocal('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 " ------------------------------------------------ " Folding stuff " ------------------------------------------------ function! VimwikiFoldListLevel(lnum) return vimwiki#lst#fold_level(a:lnum) endfunction function! VimwikiFoldLevel(lnum) let line = getline(a:lnum) " Header/section folding... if line =~# vimwiki#vars#get_syntaxlocal('rxHeader') return '>'.vimwiki#u#count_first_sym(line) " Code block folding... elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreStart') return 'a1' elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') 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 " unused function! s:shorten_text_simple(text, len) 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] " 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 " indexes on it, then use original string to break at selected index. let text_pattern = substitute(a:text, '\m\S', '.', 'g') let spare_len = a:len - strlen(text_pattern) 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(text_pattern, ' ', newlen + s:tolerance) let break_idx = (idx + s:tolerance >= newlen) ? idx : newlen return [matchstr(a:text, '\m^.\{'.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 !~# vimwiki#vars#get_syntaxlocal('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 " ------------------------------------------------ " Commands " ------------------------------------------------ command! -buffer Vimwiki2HTML \ if filewritable(expand('%')) | silent noautocmd w | endif \ \ let res = vimwiki#html#Wiki2HTML(expand(vimwiki#vars#get_wikilocal('path_html')), \ expand('%')) \ \ if res != '' | echo 'Vimwiki: HTML conversion is done, output: ' \ . expand(vimwiki#vars#get_wikilocal('path_html')) | endif command! -buffer Vimwiki2HTMLBrowse \ if filewritable(expand('%')) | silent noautocmd w | endif \ \ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML( \ expand(vimwiki#vars#get_wikilocal('path_html')), \ expand('%'))) command! -buffer VimwikiAll2HTML \ call vimwiki#html#WikiAll2HTML(expand(vimwiki#vars#get_wikilocal('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', 0, 1) command! -buffer VimwikiGoBackLink call vimwiki#base#go_back_link() command! -buffer -nargs=* VimwikiSplitLink call vimwiki#base#follow_link('hsplit', ) command! -buffer -nargs=* VimwikiVSplitLink call vimwiki#base#follow_link('vsplit', ) command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link() command! -buffer VimwikiTabnewLink call vimwiki#base#follow_link('tab', 0, 1) command! -buffer VimwikiGenerateLinks call vimwiki#base#generate_links(1) 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(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ') exe 'command! -buffer -nargs=* VWS lvimgrep '. \ escape(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('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 VimwikiToggleRejectedListItem \ call vimwiki#lst#toggle_rejected_cb(, ) command! -buffer -range VimwikiIncrementListItem call vimwiki#lst#increment_cb(, ) command! -buffer -range VimwikiDecrementListItem call vimwiki#lst#decrement_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 -nargs=? VimwikiTableAlignQ call vimwiki#tbl#align_or_cmd('gqq', ) command! -buffer -nargs=? 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 -bang VimwikiRebuildTags call vimwiki#tags#update_tags(1, '') command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags \ VimwikiSearchTags VimwikiSearch /::/ command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags \ VimwikiGenerateTags call vimwiki#tags#generate_tags(1, ) command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p')) command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p')) " ------------------------------------------------ " Keybindings " ------------------------------------------------ if vimwiki#vars#get_global('use_mouse') nmap nmap nnoremap <2-LeftMouse> \ :call vimwiki#base#follow_link('nosplit', 0, 1, "\2-LeftMouse>") nnoremap :VimwikiSplitLink nnoremap :VimwikiVSplitLink nnoremap :VimwikiGoBackLink endif if !hasmapto('Vimwiki2HTML') exe 'nmap '.vimwiki#vars#get_global('map_prefix').'h Vimwiki2HTML' endif nnoremap