vim-signify/plugin/signify.vim

140 lines
4.5 KiB
VimL
Raw Normal View History

2013-09-30 10:19:31 +02:00
" vim: et sw=2 sts=2
scriptencoding utf-8
2013-03-07 13:12:01 +01:00
2014-10-04 15:55:49 +02:00
if exists('g:loaded_signify') || !has('signs') || &compatible
2013-03-05 19:48:21 +01:00
finish
endif
2014-10-04 15:55:49 +02:00
" Init: values {{{1
2013-03-05 19:48:21 +01:00
let g:loaded_signify = 1
let g:signify_locked = 0
2013-03-05 19:48:21 +01:00
2013-04-02 16:18:01 +02:00
" Init: autocmds {{{1
augroup signify
autocmd!
2013-03-13 19:23:47 +01:00
autocmd VimEnter * call sy#highlight#setup()
autocmd BufRead,BufEnter,SessionLoadPost * let b:sy_path = resolve(expand('<afile>:p'))
autocmd BufRead,BufWritePost * call sy#start()
2014-10-04 15:55:49 +02:00
autocmd BufDelete * call sy#stop()
2013-04-03 10:31:37 +02:00
autocmd QuickFixCmdPre *vimgrep* let g:signify_locked = 1
autocmd QuickFixCmdPost *vimgrep* let g:signify_locked = 0
if get(g:, 'signify_update_on_bufenter')
2014-10-04 15:55:49 +02:00
autocmd BufEnter * nested call s:save()
endif
2013-04-03 10:31:37 +02:00
if get(g:, 'signify_cursorhold_normal')
2014-10-04 15:55:49 +02:00
autocmd CursorHold * nested call s:save()
endif
2013-04-03 10:31:37 +02:00
if get(g:, 'signify_cursorhold_insert')
2014-10-04 15:55:49 +02:00
autocmd CursorHoldI * nested call s:save()
2013-04-03 01:32:51 -04:00
endif
if get(g:, 'signify_update_on_focusgained') && !has('gui_win32')
autocmd FocusGained * call s:refresh_windows()
2013-03-13 14:06:52 -04:00
endif
augroup END
2013-03-05 19:48:21 +01:00
2013-04-02 16:18:01 +02:00
" Init: commands {{{1
com! -nargs=0 -bar SignifyToggle call sy#toggle()
com! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggle()
com! -nargs=0 -bar SyDebug call sy#debug#list_active_buffers()
2013-03-05 19:48:21 +01:00
2013-04-02 16:18:01 +02:00
" Init: mappings {{{1
2014-10-06 01:32:10 +02:00
nnoremap <silent> <plug>(signify-toggle) :<c-u>call sy#toggle()<cr>
nnoremap <silent> <plug>(signify-toggle-highlight) :<c-u>call sy#highlight#line_toggle()<cr>
if exists('g:signify_mapping_toggle')
execute 'nmap '. g:signify_mapping_toggle .' <plug>(signify-toggle)'
elseif !hasmapto('<plug>(signify-toggle)') && empty(maparg('<leader>gt', 'n'))
nmap <leader>gt <plug>(signify-toggle)
endif
if exists('g:signify_mapping_toggle_highlight')
execute 'nmap '. g:signify_mapping_toggle_highlight .' <plug>(signify-toggle-highlight)'
elseif !hasmapto('<plug>(signify-toggle-highlight)') && empty(maparg('<leader>gh', 'n'))
nmap <leader>gh <plug>(signify-toggle-highlight)
endif
" hunk jumping
nnoremap <silent> <expr> <plug>(signify-next-hunk) &diff ? ']c' : ":\<c-u>call sy#jump#next_hunk(v:count1)\<cr>"
nnoremap <silent> <expr> <plug>(signify-prev-hunk) &diff ? '[c' : ":\<c-u>call sy#jump#prev_hunk(v:count1)\<cr>"
if empty(maparg(']c', 'n'))
nmap ]c <plug>(signify-next-hunk)
endif
if empty(maparg('[c', 'n'))
nmap [c <plug>(signify-prev-hunk)
endif
2013-04-02 16:18:01 +02:00
if exists('g:signify_mapping_next_hunk')
execute 'nmap '. g:signify_mapping_next_hunk .' <plug>(signify-next-hunk)'
elseif !hasmapto('<plug>(signify-next-hunk)') && empty(maparg('<leader>gj', 'n'))
nmap <leader>gj <plug>(signify-next-hunk)
2013-04-02 16:18:01 +02:00
endif
if exists('g:signify_mapping_prev_hunk')
execute 'nmap '. g:signify_mapping_prev_hunk .' <plug>(signify-prev-hunk)'
elseif !hasmapto('<plug>(signify-prev-hunk)') && empty(maparg('<leader>gk', 'n'))
nmap <leader>gk <plug>(signify-prev-hunk)
2013-04-02 16:18:01 +02:00
endif
" hunk text object
onoremap <silent> <plug>(signify-motion-inner-pending) :<c-u>call <sid>hunk_text_object(0)<cr>
xnoremap <silent> <plug>(signify-motion-inner-visual) :<c-u>call <sid>hunk_text_object(0)<cr>
onoremap <silent> <plug>(signify-motion-outer-pending) :<c-u>call <sid>hunk_text_object(1)<cr>
xnoremap <silent> <plug>(signify-motion-outer-visual) :<c-u>call <sid>hunk_text_object(1)<cr>
if !hasmapto('<plug>(signify-motion-inner-pending)') && empty(maparg('ic', 'o'))
omap ic <plug>(signify-motion-inner-pending)
endif
if !hasmapto('<plug>(signify-motion-inner-visual)') && empty(maparg('ic', 'v'))
xmap ic <plug>(signify-motion-inner-visual)
endif
if !hasmapto('<plug>(signify-motion-outer-pending)') && empty(maparg('ac', 'o'))
omap ac <plug>(signify-motion-outer-pending)
endif
if !hasmapto('<plug>(signify-motion-outer-visual)') && empty(maparg('ac', 'v'))
xmap ac <plug>(signify-motion-outer-visual)
2013-04-02 16:18:01 +02:00
endif
2014-10-04 15:55:49 +02:00
" Function: save {{{1
function! s:save()
if exists('b:sy') && b:sy.active && &modified
write
endif
endfunction
2014-10-05 23:58:59 +02:00
" Function: refresh_windows {{{1
function! s:refresh_windows() abort
let winnr = winnr()
windo if exists('b:sy') | call sy#start() | endif
execute winnr .'wincmd w'
endfunction
" Function: hunk_text_object {{{1
2014-10-05 23:58:59 +02:00
function! s:hunk_text_object(emptylines) abort
if !exists('b:sy')
return
endif
let lnum = line('.')
let hunks = filter(copy(b:sy.hunks), 'v:val.start <= lnum && v:val.end >= lnum')
if empty(hunks)
return
endif
execute hunks[0].start
normal! V
if a:emptylines
let lnum = hunks[0].end
while getline(lnum+1) =~ '^$'
let lnum += 1
endwhile
execute lnum
else
execute hunks[0].end
endif
endfunction