" 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() " 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 " MISC }}} " GOTO FILE: gf {{{ execute 'setlocal suffixesadd='.VimwikiGet('ext') setlocal isfname-=[,] " gf}}} " Autocreate list items {{{ " for bulleted and numbered list items, and list items with checkboxes 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 l_o = matchstr(&langmap, '\C,\zs.\zeo,') if l_o exe 'nnoremap '.l_o.' :call vimwiki#lst#kbd_o()a' endif let l_O = matchstr(&langmap, '\C,\zs.\zeO,') if l_O exe 'nnoremap '.l_O.' :call vimwiki#lst#kbd_O()a' endif endif " COMMENTS }}} " 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 \ silent w \ let res = vimwiki#vw2html#Wiki2HTML(expand(VimwikiGet('path_html')), \ expand('%')) \ \ if res != '' | echo 'Vimwiki: HTML conversion is done.' | endif command! -buffer Vimwiki2HTMLBrowse \ silent w \ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML( \ expand(VimwikiGet('path_html')), \ expand('%'))) command! -buffer VimwikiAll2HTML \ call vimwiki#vw2html#WikiAll2HTML(expand(VimwikiGet('path_html'))) 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 -range VimwikiToggleCheckbox call vimwiki#lst#toggle_cb(, ) 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=1 VimwikiGoto call vimwiki#base#goto("") " list commands command! -buffer -range -nargs=+ VimwikiListChangeMarker call vimwiki#lst#change_marker(, , ) command! -buffer -nargs=1 VimwikiListChangeMarkerInList call vimwiki#lst#change_marker_in_list() command! -buffer -nargs=+ VimwikiListLineBreak call CR() command! -buffer -range -nargs=1 VimwikiListIncreaseLvl call vimwiki#lst#change_level(, , 'increase', ) command! -buffer -range -nargs=1 VimwikiListDecreaseLvl call vimwiki#lst#change_level(, , 'decrease', ) command! -buffer -range VimwikiListRemoveCB call vimwiki#lst#remove_cb(, ) " 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() " 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') nmap wh Vimwiki2HTML endif nnoremap