vimwiki/ftplugin/vimwiki.vim
Maxim Kim bb1f5b3c46 Version 0.9.9
* NEW: Diary. Help in making daily notes. See ':h vimwiki-diary'. Now you
  can really easy add information into vimwiki that should be sorted out
  later.
* NEW: Tables are redesigned. Syntax is changed. Now they are
  auto-formattable. You can navigate them with <tab> and <cr> in insert
  mode. See 'vimwiki-syntax-tables' and 'vimwiki-tables' for more details.
* NEW: Keyword STARTED: is added.
* NEW: Words TODO:, DONE:, STARTED:, XXX:, FIXME:, FIXED: are highlighed
  inside headers.
* FIX: Export to html external links with 'file://' protocol. Ex:
  '[file:///home/user1/book.pdf my book]'.
* FIX: Menu is corrupted if wiki's path contains spaces.
* FIX: Settings 'wrap' and 'linebreak' are removed from ftplugin. Add them
  into your personal settings file '.vim/after/ftplugin/vimwiki.vim' if
  needed.
* NEW: Headers are highlighted in different colors by default.  See ':h
  g:vimwiki_hl_headers' to turn it off.
* FIX: Issue 40: Links with russian subdirs don't work.
* NEW: It is now possible to generate HTML files automatically on page
  save. See ':h vimwiki-option-auto_export'.
0001-01-01 00:00:00 +00:00

323 lines
8.9 KiB
VimL

" 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 ".
\ "suffixesadd< isfname< comments< ".
\ "autowriteall< ".
\ "formatoptions< foldtext< ".
\ "foldmethod< foldexpr< commentstring< "
" UNDO }}}
" MISC STUFF {{{
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 <buffer> <expr> <CR> vimwiki_lst#insertCR()
nnoremap <buffer> o :call vimwiki_lst#insertOo('o')<CR>a
nnoremap <buffer> 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'), ' ')
" table commands
command! -buffer -nargs=* VimwikiTable call vimwiki_tbl#create(<f-args>)
command! -buffer VimwikiTableAlignQ call vimwiki_tbl#align_or_cmd('gqq')
command! -buffer VimwikiTableAlignW call vimwiki_tbl#align_or_cmd('gww')
" 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>
" Table mappings
if g:vimwiki_table_auto_fmt
inoremap <expr> <buffer> <CR> vimwiki_tbl#kbd_cr()
inoremap <expr> <buffer> <Tab> vimwiki_tbl#kbd_tab()
endif
nnoremap <buffer> gqq :VimwikiTableAlignQ<CR>
nnoremap <buffer> gww :VimwikiTableAlignW<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 }}}
" AUTOCOMMANDS {{{
if VimwikiGet('auto_export')
" Automatically generate HTML on page write.
augroup vimwiki
au BufWritePost <buffer> Vimwiki2HTML
augroup END
endif
" AUTOCOMMANDS }}}