From 32a433245e2b69377127d7158b5c5205a69cb269 Mon Sep 17 00:00:00 2001 From: Konstantin Gorodinskii Date: Fri, 22 Sep 2023 02:04:55 +0200 Subject: [PATCH] add support for tables without borders i.e. ``` header 1|header 2 --|-- data 1|data 2 ``` --- ftplugin/markdown.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index fc3fa4d9..4c84e71d 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -538,6 +538,15 @@ endfunction " function! s:TableFormat() let l:pos = getpos('.') + + normal! { + call search('|') + execute 'silent .,''}s/\v^(\s{0,})\|?([^\|])/\1|\2/e' + + normal! { + call search('|') + execute 'silent .,''}s/\v([^\|])\|?(\s{0,})$/\1|\2/e' + normal! { " Search instead of `normal! j` because of the table at beginning of file edge case. call search('|') @@ -765,7 +774,7 @@ 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! -range TableFormat '<,'> call s:TableFormat() command! -buffer Toc call s:Toc() command! -buffer Toch call s:Toc('horizontal') command! -buffer Tocv call s:Toc('vertical')