diff options
| author | jdhao <jdhao@hotmail.com> | 2021-02-23 23:33:59 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2021-02-23 23:33:59 +0800 |
| commit | 1e96062c603e0b2b09896d235ff54192bc8aeb91 (patch) | |
| tree | 53e4ef549a4f29247f66afb3561e0e06d570ce3e /after/ftplugin | |
| parent | 12bc009d2d61b76453bfc6c37f50f7beb2fe897b (diff) | |
Add mappings for Markdown
Use + to turn lines to an unordered list quickly.
Diffstat (limited to 'after/ftplugin')
| -rw-r--r-- | after/ftplugin/markdown.vim | 28 |
1 files changed, 28 insertions, 0 deletions
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 <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR> xnoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR> onoremap <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR> onoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR> + +" Use + to turn several lines to an unordered list. +nnoremap <buffer><silent> + :set operatorfunc=AddListSymbol<CR>g@ +xnoremap <buffer><silent> + :<C-U> call AddListSymbol(visualmode(), 1)<CR> + +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 |
