commit c242cb63699d8d1e4e3eb100127621d4269f557e (tree)
parent ff058bf5b7a2c4f21ea44c2e8abfc0e943c5f6e5
Author: Tim Pope <code@tpope.net>
Date: Sun, 18 Aug 2019 10:48:15 -0400
Provide maps to find similar diff lines
Diffstat:
2 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -146,31 +146,33 @@ endfunction
let s:nowait = v:version >= 704 ? '<nowait>' : ''
function! s:Map(mode, lhs, rhs, ...) abort
- let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
- let head = a:lhs
- let tail = ''
- let keys = get(g:, a:mode.'remap', {})
- if type(keys) == type([])
- return
- endif
- while !empty(head)
- if has_key(keys, head)
- let head = keys[head]
- if empty(head)
- return
+ 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 <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
- break
- endif
- let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
- 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
+ endfor
endfunction
" Section: Quickfix
@@ -2831,6 +2833,23 @@ function! s:PreviousSectionEnd(count) abort
return search('^.', 'Wb')
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
if &filetype !=# 'fugitive'
return ''
@@ -5446,6 +5465,8 @@ function! fugitive#MapJumps(...) abort
call s:MapMotion(']]', 'exe <SID>NextSection(v:count1)')
call s:MapMotion('[]', 'exe <SID>PreviousSectionEnd(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
call s:Map('n', 'S', ':<C-U>echoerr "Use gO"<CR>', '<silent>')
call s:Map('n', 'dq', ":<C-U>call <SID>DiffClose()<CR>", '<silent>')
diff --git a/doc/fugitive.txt b/doc/fugitive.txt
@@ -394,6 +394,14 @@ i Jump to the next file or hunk, expanding inline diffs
*fugitive_][*
][ 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*
gu Jump to file [count] in the "Untracked" or "Unstaged"
section.