aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-14 20:04:54 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-14 20:04:54 +1200
commit3102cf30db49602baa4e4e665622d91ff339ea1e (patch)
tree475dcc0c6f9edbcd855dd138e9998a2963a2c944 /vim
parent2985baeea1e41f87eba6c695bed848493d3ac9c8 (diff)
downloaddotfiles-3102cf30db49602baa4e4e665622d91ff339ea1e.tar.gz
dotfiles-3102cf30db49602baa4e4e665622d91ff339ea1e.zip
Expand and comment quoting functions
Diffstat (limited to 'vim')
-rw-r--r--vim/autoload/quote.vim23
1 files changed, 21 insertions, 2 deletions
diff --git a/vim/autoload/quote.vim b/vim/autoload/quote.vim
index 92de5035..6e943091 100644
--- a/vim/autoload/quote.vim
+++ b/vim/autoload/quote.vim
@@ -1,11 +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(''']'))
- let l:line = getline(l:li)
- call setline(l:li, '>'.l: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