X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/3d76a59bd0faf62ad280b9ea82117e4a0425c61f..c451b411134f97b9cbfc7bea57b034d28e29d351:/ftplugin/mkd.vim diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 2129203..41787f0 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -302,21 +302,21 @@ function! s:Markdown_Toc(...) endif try - silent vimgrep /\(^\S.*\(\n[=-]\+\)\@=\|^#\+\)/ % + silent lvimgrep /\(^\S.*\(\n[=-]\+\n\)\@=\|^#\+\)/ % catch /E480/ echom "Toc: No headers." return endtry if l:window_type ==# 'horizontal' - copen + lopen elseif l:window_type ==# 'vertical' - vertical copen + vertical lopen let &winwidth=(&columns/2) elseif l:window_type ==# 'tab' - tab copen + tab lopen else - copen + lopen endif set modifiable %s/\v^([^|]*\|){2,2} #// @@ -396,6 +396,22 @@ function! s:HeaderDecrease(line1, line2, ...) endfor endfunction +" Format table under cursor. +" Depends on Tabularize. +function! s:TableFormat() + let l:pos = getpos('.') + normal! { + " Search instead of `normal! j` because of the table at beginning of file edge case. + call search('|') + normal! j + " Remove everything that is not a pipe othewise well formated tables would grow + " because of addition of 2 spaces on the separator line by Tabularize /|. + s/[^|]//g + Tabularize /| + s/ /-/g + call setpos('.', l:pos) +endfunction + call MapNormVis('(Markdown_MoveToNextHeader)', 'Markdown_MoveToNextHeader') call MapNormVis('(Markdown_MoveToPreviousHeader)', 'Markdown_MoveToPreviousHeader') call MapNormVis('(Markdown_MoveToNextSiblingHeader)', 'Markdown_MoveToNextSiblingHeader') @@ -421,10 +437,11 @@ if !get(g:, 'vim_markdown_no_default_key_mappings', 0) vmap ]c (Markdown_MoveToCurHeader) endif +command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, ) +command! -buffer -range=% HeaderIncrease call s:HeaderDecrease(, , 1) +command! -buffer -range=% SetexToAtx call s:SetexToAtx(, ) +command! -buffer TableFormat call s:TableFormat() command! -buffer Toc call s:Markdown_Toc() command! -buffer Toch call s:Markdown_Toc('horizontal') command! -buffer Tocv call s:Markdown_Toc('vertical') command! -buffer Toct call s:Markdown_Toc('tab') -command! -buffer -range=% SetexToAtx call s:SetexToAtx(, ) -command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, ) -command! -buffer -range=% HeaderIncrease call s:HeaderDecrease(, , 1)