From 9c539c41dcfdf68e5573fc7c9d64e5d2d1db5e5a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 19:38:52 +1200 Subject: Rearrange/correct markdown_autoformat.vim --- vim/after/ftplugin/markdown/autoformat.vim | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'vim/after/ftplugin') diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index b2152336..78a2c23a 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -38,8 +38,9 @@ if !has('*s:Load') endif endfunction endif +call s:Load() -" Suspend auto-format when pasting anything with a linebreak +" Suspend auto-formatting when in a code block (four-space indent) if !has('*s:Line') function! s:Line() abort if getline('.') =~# '\m^ ' @@ -53,8 +54,14 @@ if !has('*s:Line') endif endfunction endif +augroup ftplugin_markdown_autoformat + autocmd! + autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ + \ call s:Line() +augroup END -" Suspend auto-formatting when in a code block (four-space indent) +" Suspend auto-format when pasting anything with a linebreak if !has('*s:Put') function! s:Put(above) abort let l:suspended = 0 @@ -72,23 +79,6 @@ if !has('*s:Put') endif endfunction endif - -" Turn on autoformatting if the buffer has no code-block lines with spaces -" that is longer than 'textwidth' -call s:Load() - -" Group autocommands -augroup ftplugin_markdown_autoformat - autocmd! - - " Suspend auto-formatting when in a code block (four-space indent) - autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call s:Line() - -augroup END - -" Suspend auto-format when pasting anything with a linebreak nnoremap \ p \ :call Put(0) -- cgit v1.2.3