aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/delimit_operator.vim
blob: 026fe63f6ffc7c0b4ed0c115e29ab95b820f0079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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