mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 12:53:52 -05:00
Provide literally named <Plug> maps
For every map X, also provide a map <Plug>fugitive:X. References: https://github.com/tpope/vim-fugitive/issues/1425
This commit is contained in:
@@ -208,9 +208,13 @@ let s:nowait = v:version >= 704 ? '<nowait>' : ''
|
||||
|
||||
function! s:Map(mode, lhs, rhs, ...) abort
|
||||
let maps = []
|
||||
let unique = a:0 && a:1 =~# '<unique>'
|
||||
let flags = substitute(a:0 ? a:1 : '', '<unique>', '', '') . (a:rhs =~# '<Plug>' ? '' : '<script>') . s:nowait
|
||||
for mode in split(a:mode, '\zs')
|
||||
if a:0 <= 1
|
||||
call add(maps, mode.'map <buffer>' . substitute(flags, '<unique>', '', '') . ' <Plug>fugitive:' . a:lhs . ' ' . a:rhs)
|
||||
endif
|
||||
let skip = 0
|
||||
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
|
||||
let head = a:lhs
|
||||
let tail = ''
|
||||
let keys = get(g:, mode.'remap', {})
|
||||
@@ -226,8 +230,8 @@ function! s:Map(mode, lhs, rhs, ...) abort
|
||||
let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
|
||||
let head = substitute(head, '<[^<>]*>$\|.$', '', '')
|
||||
endwhile
|
||||
if !skip && (flags !~# '<unique>' || empty(mapcheck(head.tail, mode)))
|
||||
call add(maps, mode.'map <buffer>' . s:nowait . substitute(flags, '<unique>', '', '') . ' ' . head.tail . ' ' . a:rhs)
|
||||
if !skip && (!unique || empty(mapcheck(head.tail, mode)))
|
||||
call add(maps, mode.'map <buffer>' . flags . ' ' . head.tail . ' ' . a:rhs)
|
||||
if a:0 > 1 && a:2
|
||||
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') .
|
||||
\ '|sil! exe "' . mode . 'unmap <buffer> ' . head.tail . '"'
|
||||
|
||||
@@ -732,3 +732,5 @@ 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>')
|
||||
nmap <script><silent> <Plug>fugitive:y<C-G> :<C-U>call setreg(v:register, fugitive#Object(@%))<CR>
|
||||
nmap <script> <Plug>fugitive: <Nop>
|
||||
|
||||
Reference in New Issue
Block a user