X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/8c609c8af79d81b34cb139c44017e6d881696d85..378a083529a00be1150e7591747a7cec9c467af7:/ftplugin/mkd.vim diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 0627cc5..07f81db 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -294,6 +294,39 @@ function! b:Markdown_MoveToPreviousSiblingHeader() endif endfunction +function! b:Markdown_Toc(...) + if a:0 > 0 + let l:window_type = a:1 + else + let l:window_type = 'vertical' + endif + silent vimgrep '^#' % + if l:window_type ==# 'horizontal' + copen + elseif l:window_type ==# 'vertical' + vertical copen + let &winwidth=(&columns/2) + elseif l:window_type ==# 'tab' + tab copen + else + copen + endif + set modifiable + %s/\v^([^|]*\|){2,2} #// + for i in range(1, line('$')) + let l:line = getline(i) + let l:header = matchstr(l:line, '^#*') + let l:length = len(l:header) + let l:line = substitute(l:line, '\v^#*[ ]*', '', '') + let l:line = substitute(l:line, '\v[ ]*#*$', '', '') + let l:line = repeat(' ', (2 * l:length)) . l:line + call setline(i, l:line) + endfor + set nomodified + set nomodifiable + normal! gg +endfunction + " Wrapper to do move commands in visual mode. " function! s:VisMove(f) @@ -318,8 +351,8 @@ call MapNormVis('(Markdown_MoveToParentHeader)', 'b:Markdown_MoveToPa " Menmonic: Current call MapNormVis('(Markdown_MoveToCurHeader)', 'b:Markdown_MoveToCurHeader') -if ! exists('g:markdown_no_default_key_mappings') -\ || !g:markdown_no_default_key_mappings +if ! exists('g:vim_markdown_no_default_key_mappings') +\ || !g:vim_markdown_no_default_key_mappings nmap ]] (Markdown_MoveToNextHeader) nmap [[ (Markdown_MoveToPreviousHeader) nmap ][ (Markdown_MoveToNextSiblingHeader) @@ -334,3 +367,8 @@ if ! exists('g:markdown_no_default_key_mappings') vmap ]u (Markdown_MoveToParentHeader) vmap ]c (Markdown_MoveToCurHeader) endif + +command! -buffer Toc call b:Markdown_Toc() +command! -buffer Toch call b:Markdown_Toc('horizontal') +command! -buffer Tocv call b:Markdown_Toc('vertical') +command! -buffer Toct call b:Markdown_Toc('tab')