" Only do this when not done yet for this buffer " Also do nothing if 'compatible' enabled, or if no autocmd feature, or if Vim " is too old to support the needed autocmd events if exists('b:did_ftplugin_markdown_autoformat') || &compatible finish endif if !has('autocmd') || v:version < 700 finish endif let b:did_ftplugin_markdown_autoformat = 1 if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin \ . '|unlet b:did_ftplugin_markdown_autoformat' endif " Suspend auto-formatting when in a code block (four-space indent) autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter \ \ call ftplugin#markdown#autoformat#Line() " Suspend auto-format when pasting anything with a linebreak nnoremap \ p \ :call ftplugin#markdown#autoformat#PutBelow() nnoremap \ P \ :call ftplugin#markdown#autoformat#PutAbove() " Undo all the above if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin \ . '|setlocal formatoptions<' endif