spacevim/bundle/vim-matchup/autoload/matchup/surround.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

84 lines
2.3 KiB
VimL

" vim match-up - even better matching
"
" Maintainer: Andy Massimino
" Email: a@normed.space
"
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
function! matchup#surround#delimited(is_cap, op, type) " {{{1
call matchup#perf#timeout_start(1000)
let [l:open, l:close] = matchup#delim#get_surrounding(
\ a:type, v:count, { 'local': 0 })
if empty(l:open) || empty(l:close)
return
endif
if a:op ==# 'c'
let l:char = nr2char(getchar())
if index(["\<esc>","\<c-c>"], l:char) >= 0
return
endif
endif
let l:tpope = !empty(maparg('<plug>VSurround', 'x'))
let [l:l1, l:c11, l:c12] = [l:open.lnum, l:open.cnum,
\ l:open.cnum + strlen(l:open.match) - 1]
let [l:l2, l:c21, l:c22] = [l:close.lnum, l:close.cnum,
\ l:close.cnum + strlen(l:close.match) - 1]
if a:op ==# 'd' || a:op ==# 'c'
call matchup#pos#set_cursor(l1, c12+1)
let [l:insl, l:insr] = ['', '']
if a:op ==# 'c' && !l:tpope
let l:idx = index(s:pairtrans, l:char)
let l:insl = l:idx < 0 ? l:char : s:pairtrans[l:idx/2*2]
let l:insr = l:idx < 0 ? l:char : s:pairtrans[l:idx/2*2+1]
endif
let l:line = getline(l:l2)
call setline(l:l2, strpart(l:line, 0, l:c21-1)
\ . l:insr . strpart(l:line, l:c22))
let l:regtext = strpart(l:line, l:c21-1, l:c22-l:c21+1)
let l:line = getline(l:l1)
call setline(l:l1, strpart(l:line, 0, l:c11-1)
\ . l:insl . strpart(l:line, l:c12))
call setreg(v:register, strpart(l:line, l:c11-1, l:c12-l:c11+1)
\ . ' ' . l:regtext)
let l:epos = l:c21-1 - (l:l1 == l:l2
\ ? (l:c12-l:c11+1-strlen(l:insl)-strlen(l:insr)) : 0)
call setpos("']", [0, l:l2, l:epos, 0])
call setpos("'[", [0, l:l1, l:c11, 0])
endif
if a:op ==# 'd' || a:op ==# 'c' && empty(l:char)
silent! call repeat#set("\<plug>(matchup-ds%)", v:count)
elseif a:op ==# 'c' && l:tpope
normal! `[v`]
undojoin
execute "normal \<plug>VSurround".l:char
silent! call repeat#set("\<plug>(matchup-cs%)"
\ . matchstr(g:repeat_sequence, 'SSurroundRepeat\zs.\+'),
\ v:count)
endif
call matchup#pos#set_cursor(l1, c11)
endfunction
let s:pairtrans = split('()<>[]{}«»“”', '\ze')
" }}}1
let &cpo = s:save_cpo
" vim: fdm=marker sw=2