X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/55698854abe296deb5b698e9d2d1c2a92549aa77..2b4603e9eaac622ee963c45b3a838e36bd7b7b1f:/ftplugin/mkd.vim diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 2129203..36d0b08 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -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)