diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index d095cd7..b025161 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -16,6 +16,7 @@ endfunction " Finds the file's path relative to the repo root. function! gitgutter#init_buffer(bufnr) if gitgutter#utility#is_active(a:bufnr) + call s:setup_maps() let p = gitgutter#utility#repo_path(a:bufnr, 0) if type(p) != s:t_string || empty(p) call gitgutter#utility#set_repo_path(a:bufnr) @@ -81,6 +82,42 @@ endfunction " }}} +function! s:setup_maps() + if !g:gitgutter_map_keys + return + endif + + if !hasmapto('GitGutterPrevHunk') && maparg('[c', 'n') ==# '' + nmap [c GitGutterPrevHunk + endif + if !hasmapto('GitGutterNextHunk') && maparg(']c', 'n') ==# '' + nmap ]c GitGutterNextHunk + endif + + if !hasmapto('GitGutterStageHunk') && maparg('hs', 'n') ==# '' + nmap hs GitGutterStageHunk + endif + if !hasmapto('GitGutterUndoHunk') && maparg('hu', 'n') ==# '' + nmap hu GitGutterUndoHunk + endif + if !hasmapto('GitGutterPreviewHunk') && maparg('hp', 'n') ==# '' + nmap hp GitGutterPreviewHunk + endif + + if !hasmapto('GitGutterTextObjectInnerPending') && maparg('ic', 'o') ==# '' + omap ic GitGutterTextObjectInnerPending + endif + if !hasmapto('GitGutterTextObjectOuterPending') && maparg('ac', 'o') ==# '' + omap ac GitGutterTextObjectOuterPending + endif + if !hasmapto('GitGutterTextObjectInnerVisual') && maparg('ic', 'x') ==# '' + xmap ic GitGutterTextObjectInnerVisual + endif + if !hasmapto('GitGutterTextObjectOuterVisual') && maparg('ac', 'x') ==# '' + xmap ac GitGutterTextObjectOuterVisual + endif +endfunction + function! s:has_fresh_changes(bufnr) abort return getbufvar(a:bufnr, 'changedtick') != gitgutter#utility#getbufvar(a:bufnr, 'tick') endfunction diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 53eb44c..ec2215c 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -167,45 +167,10 @@ command! -bar GitGutterDebug call gitgutter#debug#debug() nnoremap GitGutterNextHunk &diff ? ']c' : ":\execute v:count1 . 'GitGutterNextHunk'\" nnoremap GitGutterPrevHunk &diff ? '[c' : ":\execute v:count1 . 'GitGutterPrevHunk'\" -if g:gitgutter_map_keys - if !hasmapto('GitGutterPrevHunk') && maparg('[c', 'n') ==# '' - nmap [c GitGutterPrevHunk - endif - if !hasmapto('GitGutterNextHunk') && maparg(']c', 'n') ==# '' - nmap ]c GitGutterNextHunk - endif -endif - - nnoremap GitGutterStageHunk :GitGutterStageHunk nnoremap GitGutterUndoHunk :GitGutterUndoHunk nnoremap GitGutterPreviewHunk :GitGutterPreviewHunk -if g:gitgutter_map_keys - if !hasmapto('GitGutterStageHunk') && maparg('hs', 'n') ==# '' - nmap hs GitGutterStageHunk - endif - if !hasmapto('GitGutterUndoHunk') && maparg('hu', 'n') ==# '' - nmap hu GitGutterUndoHunk - endif - if !hasmapto('GitGutterPreviewHunk') && maparg('hp', 'n') ==# '' - nmap hp GitGutterPreviewHunk - endif - - if !hasmapto('GitGutterTextObjectInnerPending') && maparg('ic', 'o') ==# '' - omap ic GitGutterTextObjectInnerPending - endif - if !hasmapto('GitGutterTextObjectOuterPending') && maparg('ac', 'o') ==# '' - omap ac GitGutterTextObjectOuterPending - endif - if !hasmapto('GitGutterTextObjectInnerVisual') && maparg('ic', 'x') ==# '' - xmap ic GitGutterTextObjectInnerVisual - endif - if !hasmapto('GitGutterTextObjectOuterVisual') && maparg('ac', 'x') ==# '' - xmap ac GitGutterTextObjectOuterVisual - endif -endif - " }}} " Autocommands {{{