aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-01-04 14:55:19 +1300
committerTom Ryder <tom@sanctum.geek.nz>2019-01-04 14:55:19 +1300
commit6ed48b12e451a0770d5a3f236e66e0e7e9a39c8d (patch)
treef63a011a642d8bdaa75aee6d87c17306784244bc /vim/autoload
parentMerge branch 'hotfix/v4.6.1' into develop (diff)
downloaddotfiles-6ed48b12e451a0770d5a3f236e66e0e7e9a39c8d.tar.gz
dotfiles-6ed48b12e451a0770d5a3f236e66e0e7e9a39c8d.zip
Add experimental delimit_operator.vim plugin
This is an attempt at a small subset of surround.vim's behaviour, hopefully drastically simplified. I'm not actually sure how useful or practical this is going to be yet.
Diffstat (limited to 'vim/autoload')
-rw-r--r--vim/autoload/delimit_operator.vim50
1 files changed, 50 insertions, 0 deletions
diff --git a/vim/autoload/delimit_operator.vim b/vim/autoload/delimit_operator.vim
new file mode 100644
index 00000000..026fe63f
--- /dev/null
+++ b/vim/autoload/delimit_operator.vim
@@ -0,0 +1,50 @@
+let s:pairs = {
+ \ '(': ')',
+ \ '<': '>',
+ \ '[': ']',
+ \ '{': '}',
+ \ }
+
+function! delimit_operator#Operatorfunc(type) abort
+
+ let l:save = {
+ \ 'unnamed': @@,
+ \ 'clipboard': &clipboard,
+ \ 'selection': &selection
+ \ }
+
+ set clipboard-=unnamed
+ set clipboard-=unnamedplus
+
+ set selection=inclusive
+
+ let l:delimiters = {
+ \ 'open': s:char,
+ \ 'close': get(s:pairs, s:char, s:char)
+ \ }
+
+ if a:type ==# 'line'
+ silent normal! '[V']y
+ elseif a:type ==# 'block'
+ silent execute "normal! `[\<C-V>`]y"
+ else
+ silent normal! `[v`]y
+ endif
+
+ let @@ = l:delimiters['open']
+ \ . @@
+ \ . l:delimiters['close']
+
+ silent normal! gvp
+
+ let @@ = l:save['unnamed']
+ let &clipboard = l:save['clipboard']
+ let &selection = l:save['selection']
+
+endfunction
+
+function! delimit_operator#Map() abort
+ let s:char = nr2char(getchar())
+ set operatorfunc=delimit_operator#Operatorfunc
+ return 'g@'
+endfunction