commit 40bc5aff1812b2e6fde712a716f2393bdcabf4a4 (tree)
parent 68da9a2be309490a669bc641dbae7eda556e474b
Author: Tim Pope <code@tpope.net>
Date: Tue, 3 Sep 2019 23:56:16 -0400
Make universal maps global
Diffstat:
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -5847,10 +5847,6 @@ function! fugitive#Init() abort
let &mls = save_mls
endtry
endif
- if !exists('g:fugitive_no_maps')
- call s:Map('c', '<C-R><C-G>', '<SID>fnameescape(fugitive#Object(@%))', '<expr>')
- call s:Map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')
- endif
let dir = s:Dir()
if stridx(&tags, escape(dir, ', ')) == -1 && &tags !~# '\.git' && !exists('s:tags_warning')
let actualdir = fugitive#Find('.git/', dir)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -400,3 +400,38 @@ exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#CompleteObject G
exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#RenameComplete Grename exe fugitive#RenameCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject Gbrowse exe fugitive#BrowseCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>, [<f-args>])'
+
+if get(g:, 'fugitive_no_maps')
+ finish
+endif
+
+let s:nowait = v:version >= 704 ? '<nowait>' : ''
+
+function! s:Map(mode, lhs, rhs, ...) abort
+ for mode in split(a:mode, '\zs')
+ let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
+ let head = a:lhs
+ let tail = ''
+ let keys = get(g:, mode.'remap', {})
+ if type(keys) == type([])
+ return
+ endif
+ while !empty(head)
+ if has_key(keys, head)
+ let head = keys[head]
+ if empty(head)
+ return
+ endif
+ break
+ endif
+ let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
+ let head = substitute(head, '<[^<>]*>$\|.$', '', '')
+ endwhile
+ if flags !~# '<unique>' || empty(mapcheck(head.tail, mode))
+ exe mode.'map' s:nowait flags head.tail a:rhs
+ endif
+ endfor
+endfunction
+
+call s:Map('c', '<C-R><C-G>', 'fnameescape(fugitive#Object(@%))', '<expr>')
+call s:Map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')