diff options
Diffstat (limited to 'vim/autoload')
-rw-r--r-- | vim/autoload/mail.vim | 11 | ||||
-rw-r--r-- | vim/autoload/quote.vim | 30 |
2 files changed, 30 insertions, 11 deletions
diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim deleted file mode 100644 index 4c21ae38..00000000 --- a/vim/autoload/mail.vim +++ /dev/null @@ -1,11 +0,0 @@ -" Quote lines in mail messages -function! mail#Quote() abort - set operatorfunc=mail#QuoteOpfunc - return 'g@' -endfunction -function! mail#QuoteOpfunc(type) abort - for l:li in range(line('''['), line(''']')) - let l:line = getline(l:li) - call setline(l:li, '>'.l:line) - endfor -endfunction diff --git a/vim/autoload/quote.vim b/vim/autoload/quote.vim new file mode 100644 index 00000000..6e943091 --- /dev/null +++ b/vim/autoload/quote.vim @@ -0,0 +1,30 @@ +" Quote lines in mail and mail-based formats: Markdown, Git commits, etc + +" Operator function wrapper for the mapping to call +function! quote#Quote() abort + set operatorfunc=quote#QuoteOpfunc + return 'g@' +endfunction + +" Quoting operator function +function! quote#QuoteOpfunc(type) abort + + " May as well make this configurable + let l:char = exists('b:quote_char') + \ ? b:quote_char + \ : '>' + + " Iterate over each matched line + for l:li in range(line('''['), line(''']')) + + " Only add a space after the quote character if this line isn't already + " quoted with the same character + let l:cur = getline(l:li) + let l:new = stridx(l:cur, l:char) == 0 + \ ? l:char.l:cur + \ : l:char.' '.l:cur + call setline(l:li, l:new) + + endfor + +endfunction |