vim-signify/plugin/signify.vim
deris0126 4b1dc081d7 Do not overwrite already mapped keys
Don't set <plug> mappings twice and don't set them at all if the target
keys are already mapped.

Closes 42.
2013-07-21 18:51:00 +02:00

93 lines
3.3 KiB
VimL

" Plugin: https://github.com/mhinz/vim-signify
" Description: show a diff from a version control system via the signcolumn
" Maintainer: Marco Hinz <http://github.com/mhinz>
" Version: 1.9
if exists('g:loaded_signify') || !has('signs') || &cp
finish
endif
let g:loaded_signify = 1
" Init: values {{{1
let g:sy = {}
" Init: autocmds {{{1
augroup signify
autocmd!
autocmd VimEnter * call sy#highlight#setup()
autocmd BufRead,BufEnter * let g:sy_path = resolve(expand('<afile>:p'))
autocmd BufRead,BufWritePost * call sy#start(g:sy_path)
autocmd BufDelete *
\ let path = resolve(expand('<afile>:p')) |
\ call sy#stop(path) |
\ if has_key(g:sy, path) |
\ call remove(g:sy, path) |
\ endif
if get(g:, 'signify_update_on_bufenter')
autocmd BufEnter * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified |
\ write |
\ endif
endif
if get(g:, 'signify_cursorhold_normal')
autocmd CursorHold * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified |
\ write |
\ endif
endif
if get(g:, 'signify_cursorhold_insert')
autocmd CursorHoldI * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified |
\ write |
\ endif
endif
if !has('gui_win32')
autocmd FocusGained * call sy#start(g:sy_path)
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 -count=1 SignifyJumpToNextHunk call sy#jump#next_hunk(<count>)
com! -nargs=0 -bar -count=1 SignifyJumpToPrevHunk call sy#jump#prev_hunk(<count>)
com! -nargs=0 -bar SyDebug call sy#debug#list_active_buffers()
" Init: mappings {{{1
nnoremap <silent> <plug>(signify-next-hunk) :<C-u>call sy#jump#next_hunk(v:count1)<cr>
nnoremap <silent> <plug>(signify-prev-hunk) :<C-u>call sy#jump#prev_hunk(v:count1)<cr>
nnoremap <silent> <plug>(signify-toggle-highlight) :<C-u>call sy#highlight#line_toggle()<cr>
nnoremap <silent> <plug>(signify-toggle) :<C-u>call sy#toggle()<cr>
if exists('g:signify_mapping_next_hunk')
execute 'nnoremap '. g:signify_mapping_next_hunk .' <plug>(signify-next-hunk)'
elseif !hasmapto('<plug>(signify-next-hunk)') && empty(maparg('<leader>gj', 'n'))
nnoremap <leader>gj <plug>(signify-next-hunk)
endif
if exists('g:signify_mapping_prev_hunk')
execute 'nnoremap '. g:signify_mapping_prev_hunk .' <plug>(signify-prev-hunk)'
elseif !hasmapto('<plug>(signify-prev-hunk)') && empty(maparg('<leader>gk', 'n'))
nnoremap <leader>gk <plug>(signify-prev-hunk)
endif
if exists('g:signify_mapping_toggle_highlight')
execute 'nnoremap '. g:signify_mapping_toggle_highlight .' <plug>(signify-toggle-highlight)'
elseif !hasmapto('<plug>(signify-toggle-highlight)') && empty(maparg('<leader>gh', 'n'))
nnoremap <leader>gh <plug>(signify-toggle-highlight)
endif
if exists('g:signify_mapping_toggle')
execute 'nnoremap '. g:signify_mapping_toggle .' <plug>(signify-toggle)'
elseif !hasmapto('<plug>(signify-toggle)') && empty(maparg('<leader>gt', 'n'))
nnoremap <leader>gt <plug>(signify-toggle)
endif
" vim: et sw=2 sts=2