" vim: et sw=2 sts=2 scriptencoding utf-8 if exists('g:loaded_signify') || !has('signs') || &compatible finish endif " Init: values {{{1 let g:loaded_signify = 1 let g:signify_locked = 0 " Init: autocmds {{{1 augroup signify autocmd! autocmd VimEnter * call sy#highlight#setup() autocmd BufRead,BufEnter,SessionLoadPost * let b:sy_path = resolve(expand(':p')) autocmd BufRead,BufWritePost * call sy#start() autocmd BufDelete * call sy#stop() autocmd QuickFixCmdPre *vimgrep* let g:signify_locked = 1 autocmd QuickFixCmdPost *vimgrep* let g:signify_locked = 0 if get(g:, 'signify_update_on_bufenter') autocmd BufEnter * nested call s:save() endif if get(g:, 'signify_cursorhold_normal') autocmd CursorHold * nested call s:save() endif if get(g:, 'signify_cursorhold_insert') autocmd CursorHoldI * nested call s:save() endif if get(g:, 'signify_update_on_focusgained') && !has('gui_win32') autocmd FocusGained * call s:refresh_windows() endif augroup END " 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() " Init: mappings {{{1 nnoremap (signify-toggle) :call sy#toggle() nnoremap (signify-toggle-highlight) :call sy#highlight#line_toggle() nnoremap (signify-next-hunk) &diff ? ']c' : ":\call sy#jump#next_hunk(v:count1)\" nnoremap (signify-prev-hunk) &diff ? '[c' : ":\call sy#jump#prev_hunk(v:count1)\" if exists('g:signify_mapping_toggle') execute 'nmap '. g:signify_mapping_toggle .' (signify-toggle)' elseif !hasmapto('(signify-toggle)') && empty(maparg('gt', 'n')) nmap gt (signify-toggle) endif if exists('g:signify_mapping_toggle_highlight') execute 'nmap '. g:signify_mapping_toggle_highlight .' (signify-toggle-highlight)' elseif !hasmapto('(signify-toggle-highlight)') && empty(maparg('gh', 'n')) nmap gh (signify-toggle-highlight) endif if exists('g:signify_mapping_next_hunk') execute 'nmap '. g:signify_mapping_next_hunk .' (signify-next-hunk)' elseif !hasmapto('(signify-next-hunk)') && empty(maparg('gj', 'n')) nmap gj (signify-next-hunk) endif if exists('g:signify_mapping_prev_hunk') execute 'nmap '. g:signify_mapping_prev_hunk .' (signify-prev-hunk)' elseif !hasmapto('(signify-prev-hunk)') && empty(maparg('gk', 'n')) nmap gk (signify-prev-hunk) endif if empty(maparg(']c', 'n')) nmap ]c (signify-next-hunk) endif if empty(maparg('[c', 'n')) nmap [c (signify-prev-hunk) endif " Function: save {{{1 function! s:save() if exists('b:sy') && b:sy.active && &modified write endif endfunction " 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 " Text object: ac / ic {{{1 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 onoremap ac :call hunk_text_object(1) xnoremap ac :call hunk_text_object(1) onoremap ic :call hunk_text_object(0) xnoremap ic :call hunk_text_object(0)