From: Danqi Wang Date: Wed, 26 Mar 2014 02:36:00 +0000 (+0800) Subject: Better support for bullet insertion and auto indentation in list items. X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/5cd2223d4eec545745f729142197e839135cce94?ds=inline;hp=-c Better support for bullet insertion and auto indentation in list items. 1. Added setlocal formatoptions-=c to disable automatically inserting bullets when auto-wrapping with textwidth. 2. Added indent/mkd.vim to support auto indent in list. --- 5cd2223d4eec545745f729142197e839135cce94 diff --git a/indent/mkd.vim b/indent/mkd.vim new file mode 100755 index 0000000..a26ac0e --- /dev/null +++ b/indent/mkd.vim @@ -0,0 +1,46 @@ +if exists("b:did_indent") | finish | endif +let b:did_indent = 1 + +setlocal indentexpr=GetMkdIndent() +setlocal nolisp +setlocal nosmartindent +setlocal autoindent + +" Only define the function once +if exists("*GetMkdIndent") | finish | endif + +function! s:is_li_start(line) + return a:line =~ '^\s*[\*+-]' +endfunction + +function! s:is_blank_line(line) + return a:line =~ '^$' +endfunction + +function! s:prevnonblank(lnum) + let i = a:lnum + while i > 1 && s:is_blank_line(getline(i)) + let i -= 1 + endwhile + return i +endfunction + +function GetMkdIndent() + let list_ind = 4 + " Find a non-blank line above the current line. + let lnum = prevnonblank(v:lnum - 1) + " At the start of the file use zero indent. + if lnum == 0 | return 0 | endif + let ind = indent(lnum) + let line = getline(lnum) " Last line + let cline = getline(v:lnum) " Current line + if s:is_li_start(cline) + " Current line is the first line of a list item, do not change indent + return indent(v:lnum) + elseif s:is_li_start(line) + " Last line is the first line of a list item, increase indent + return ind + list_ind + else + return ind + endif +endfunction diff --git a/syntax/mkd.vim b/syntax/mkd.vim index d6233d2..e10bbc3 100644 --- a/syntax/mkd.vim +++ b/syntax/mkd.vim @@ -119,6 +119,8 @@ HtmlHiLink mkdDelimiter Delimiter " Automatically insert bullets setlocal formatoptions+=r +" Do not automatically insert bullets when auto-wrapping with text-width +setlocal formatoptions-=c " Accept various markers as bullets setlocal comments=b:*,b:+,b:-