Provide maps to find similar diff lines

This commit is contained in:
Tim Pope 2019-08-18 10:48:15 -04:00
parent ff058bf5b7
commit c242cb6369
2 changed files with 52 additions and 23 deletions

View File

@ -146,31 +146,33 @@ endfunction
let s:nowait = v:version >= 704 ? '<nowait>' : '' let s:nowait = v:version >= 704 ? '<nowait>' : ''
function! s:Map(mode, lhs, rhs, ...) abort function! s:Map(mode, lhs, rhs, ...) abort
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>') for mode in split(a:mode, '\zs')
let head = a:lhs let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
let tail = '' let head = a:lhs
let keys = get(g:, a:mode.'remap', {}) let tail = ''
if type(keys) == type([]) let keys = get(g:, mode.'remap', {})
return if type(keys) == type([])
endif return
while !empty(head) endif
if has_key(keys, head) while !empty(head)
let head = keys[head] if has_key(keys, head)
if empty(head) let head = keys[head]
return 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 <buffer>' s:nowait flags head.tail a:rhs
if a:0 > 1
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') .
\ '|sil! exe "' . mode . 'unmap <buffer> ' . head.tail . '"'
endif endif
break
endif endif
let tail = matchstr(head, '<[^<>]*>$\|.$') . tail endfor
let head = substitute(head, '<[^<>]*>$\|.$', '', '')
endwhile
if flags !~# '<unique>' || empty(mapcheck(head.tail, a:mode))
exe a:mode.'map <buffer>' s:nowait flags head.tail a:rhs
if a:0 > 1
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') .
\ '|sil! exe "' . a:mode . 'unmap <buffer> ' . head.tail . '"'
endif
endif
endfunction endfunction
" Section: Quickfix " Section: Quickfix
@ -2831,6 +2833,23 @@ function! s:PreviousSectionEnd(count) abort
return search('^.', 'Wb') return search('^.', 'Wb')
endfunction endfunction
function! s:PatchSearchExpr(reverse) abort
let line = getline('.')
if col('.') ==# 1 && line =~# '^[+-]'
if line =~# '^[+-]\{3\} '
let pattern = '^[+-]\{3\} ' . substitute(escape(strpart(line, 4), '^$.*[]~\'), '^\w/', '\\w/', '') . '$'
else
let pattern = '^[+-]\s*' . escape(substitute(strpart(line, 1), '^\s*\|\s*$', '', ''), '^$.*[]~\') . '\s*$'
endif
if a:reverse
return '?' . escape(pattern, '/') . "\<CR>"
else
return '/' . escape(pattern, '/?') . "\<CR>"
endif
endif
return a:reverse ? '#' : '*'
endfunction
function! s:StageInline(mode, ...) abort function! s:StageInline(mode, ...) abort
if &filetype !=# 'fugitive' if &filetype !=# 'fugitive'
return '' return ''
@ -5446,6 +5465,8 @@ function! fugitive#MapJumps(...) abort
call s:MapMotion(']]', 'exe <SID>NextSection(v:count1)') call s:MapMotion(']]', 'exe <SID>NextSection(v:count1)')
call s:MapMotion('[]', 'exe <SID>PreviousSectionEnd(v:count1)') call s:MapMotion('[]', 'exe <SID>PreviousSectionEnd(v:count1)')
call s:MapMotion('][', 'exe <SID>NextSectionEnd(v:count1)') call s:MapMotion('][', 'exe <SID>NextSectionEnd(v:count1)')
call s:Map('nxo', '*', '<SID>PatchSearchExpr(0)', '<expr>')
call s:Map('nxo', '#', '<SID>PatchSearchExpr(1)', '<expr>')
endif endif
call s:Map('n', 'S', ':<C-U>echoerr "Use gO"<CR>', '<silent>') call s:Map('n', 'S', ':<C-U>echoerr "Use gO"<CR>', '<silent>')
call s:Map('n', 'dq', ":<C-U>call <SID>DiffClose()<CR>", '<silent>') call s:Map('n', 'dq', ":<C-U>call <SID>DiffClose()<CR>", '<silent>')

View File

@ -394,6 +394,14 @@ i Jump to the next file or hunk, expanding inline diffs
*fugitive_][* *fugitive_][*
][ Jump [count] section ends forward. ][ Jump [count] section ends forward.
*fugitive_star*
* One the first column of a + or - diff line, search for
the corresponding - or + line. Otherwise, defer to
built-in |star|.
*fugitive_#*
# Same as "*", but search backward.
*fugitive_gu* *fugitive_gu*
gu Jump to file [count] in the "Untracked" or "Unstaged" gu Jump to file [count] in the "Untracked" or "Unstaged"
section. section.