diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index 09b4f4c..f0b9d80 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -14,3 +14,31 @@ xnoremap ic :call text_obj#MdCodeBlock('i') xnoremap ac :call text_obj#MdCodeBlock('a') onoremap ic :call text_obj#MdCodeBlock('i') onoremap ac :call text_obj#MdCodeBlock('a') + +" Use + to turn several lines to an unordered list. +nnoremap + :set operatorfunc=AddListSymbolg@ +xnoremap + : call AddListSymbol(visualmode(), 1) + +function! AddListSymbol(type, ...) abort + if a:0 + let line_start = line("'<") + let line_end = line("'>") + else + let line_start = line("'[") + let line_end = line("']") + endif + + " add list symbol to each line + for line in range(line_start, line_end) + let text = getline(line) + + let end = matchend(text, '^\s*') + if end == 0 + let new_text = '+ ' . text + else + let new_text = text[0:end-1] . ' + ' . text[end:] + endif + + call setline(line, new_text) + endfor +endfunction