spacevim/bundle/vim-over/autoload/over.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

174 lines
3.9 KiB
VimL

scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let g:over#debug_vital_over = get(g:, "over#debug_vital_over", 0)
function! over#load()
call over#command_line#load()
endfunction
function! over#vital()
if exists("s:V")
return s:V
endif
if g:over#debug_vital_over
let s:V = vital#of("vital")
else
let s:V = vital#over#new()
endif
return s:V
endfunction
function! over#revital()
call s:V.unload()
unlet! s:V
call over#vital()
endfunction
function! s:silent_feedkeys(expr, name, ...)
let mode = get(a:, 1, "m")
let name = "over-" . a:name
let map = printf("<Plug>(%s)", name)
if mode == "n"
let command = "nnoremap"
else
let command = "nmap"
endif
execute command "<silent>" map printf("%s:nunmap %s<CR>", a:expr, map)
call feedkeys(printf("\<Plug>(%s)", name))
endfunction
" http://d.hatena.ne.jp/thinca/20131104/1383498883
" {range}s/{pattern}/{string}/{flags}
function! s:parse_substitute(word)
let very_magic = '\v'
let range = '(.{-})'
let command = 's%[ubstitute]'
let first_slash = '([\x00-\xff]&[^\\"|[:alnum:][:blank:]])'
let pattern = '(%(\\.|.){-})'
let second_slash = '\2'
let string = '(%(\\.|.){-})'
let flags = '%(\2([&cegiInp#lr]*))?'
let parse_pattern
\ = very_magic
\ . '^:*'
\ . range
\ . command
\ . first_slash
\ . pattern
\ . '%('
\ . second_slash
\ . string
\ . flags
\ . ')?$'
let result = matchlist(a:word, parse_pattern)[1:5]
if type(result) == type(0) || empty(result)
return []
endif
unlet result[1]
return result
endfunction
" base code
" https://github.com/thinca/vim-ambicmd/blob/78fa88c5647071e73a3d21e5f575ed408f68aaaf/autoload/ambicmd.vim#L26
function! over#parse_range(string)
let search_pattern = '\v/[^/]*\\@<!%(\\\\)*/|\?[^?]*\\@<!%(\\\\)*\?'
let line_specifier =
\ '\v%(\d+|[.$]|''\S|\\[/?&])?%([+-]\d*|' . search_pattern . ')*'
let range_pattern = '\v%((\%|' . line_specifier . ')' .
\ '%([;,](' . line_specifier . '))*)'
return matchlist(a:string, range_pattern)
endfunction
function! s:search_highlight(line)
let result = s:parse_substitute(a:line)
let text = get(result, 1, "")
if !s:set_flag
let s:search_highlighted = 1
let s:set_flag = 1
call feedkeys("\<C-o>:set hlsearch | set incsearch\<CR>", 'n')
endif
let @/ = text
endfunction
function! s:set_options()
if s:search_highlighted
let s:search_highlighted = 0
return
endif
let s:old_incsearch = &incsearch
let s:old_hlsearch = &hlsearch
let s:old_search_pattern = @/
endfunction
nnoremap <silent><expr> <Plug>(over-restore-search-pattern)
\ (mode() =~ '[iR]' ? "\<C-o>" : "") . ":let @/ = " . string(s:old_search_pattern) . "\<CR>"
nnoremap <silent><expr> <Plug>(over-restore-nohlsearch)
\ (mode() =~ '[iR]' ? "\<C-o>" : "") . ":nohlsearch\<CR>"
function! s:restore_options()
if s:search_highlighted || s:set_flag == 0
return
endif
let s:set_flag = 0
let &incsearch = s:old_incsearch
let &hlsearch = s:old_hlsearch
if g:over_enable_auto_nohlsearch
call s:silent_feedkeys(":nohlsearch\<CR>", "nohlsearch", 'n')
call feedkeys("\<Plug>(over-restore-nohlsearch)")
endif
execute "normal \<Plug>(over-restore-search-pattern)"
" call s:silent_feedkeys(":let @/ = " . string(s:old_search_pattern) . "\<CR>", "restore-search-pattern", 'n')
endfunction
function! over#setup()
let s:set_flag = 0
let s:search_highlighted = 0
augroup over-cmdwindow
autocmd!
autocmd InsertCharPre * call s:search_highlight(getline(".") . v:char)
autocmd InsertEnter * call s:set_options()
autocmd InsertLeave * call s:restore_options()
augroup END
endfunction
function! over#unsetup()
augroup over-cmdwindow
autocmd!
augroup END
endfunction
function! over#command_line(prompt, input, ...)
let context = get(a:, 1, {})
return over#command_line#start(a:prompt, a:input, context)
endfunction
function! over#parse_substitute(word)
return s:parse_substitute(a:word)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo