commit 0f08b0cbbb618b6bbd05f586fef206e9a45686eb (tree)
parent 35cf80dd3b46e440126db181937baa2d1f86a266
Author: Tim Pope <code@tpope.net>
Date: Sat, 3 Aug 2019 00:52:49 -0400
Provide separate file/hunk jump maps
Diffstat:
2 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -2654,6 +2654,63 @@ endfunction
let s:file_pattern = '^[A-Z?] .\|^diff --'
let s:item_pattern = s:file_pattern . '\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@@'
+function! s:NextHunk(count) abort
+ if &filetype ==# 'fugitive' && getline('.') =~# s:file_pattern
+ exe s:StageInline('show')
+ endif
+ for i in range(a:count)
+ if &filetype ==# 'fugitive'
+ call search(s:file_pattern . '\|^@', 'W')
+ if getline('.') =~# s:file_pattern
+ exe s:StageInline('show')
+ if getline(line('.') + 1) =~# '^@'
+ +
+ endif
+ endif
+ else
+ call search('^@@', 'W')
+ endif
+ endfor
+ call s:StageReveal()
+ return '.'
+endfunction
+
+function! s:PreviousHunk(count) abort
+ for i in range(a:count)
+ if &filetype ==# 'fugitive'
+ let lnum = search(s:file_pattern . '\|^@','Wbn')
+ call s:StageInline('show', lnum)
+ call search('^? .\|^@','Wb')
+ else
+ call search('^@@', 'Wb')
+ endif
+ endfor
+ call s:StageReveal()
+ return '.'
+endfunction
+
+function! s:NextFile(count) abort
+ for i in range(a:count)
+ exe s:StageInline('hide')
+ if !search(s:file_pattern, 'W')
+ break
+ endif
+ endfor
+ exe s:StageInline('hide')
+ return '.'
+endfunction
+
+function! s:PreviousFile(count) abort
+ exe s:StageInline('hide')
+ for i in range(a:count)
+ if !search(s:file_pattern, 'Wb')
+ break
+ endif
+ exe s:StageInline('hide')
+ endfor
+ return '.'
+endfunction
+
function! s:NextItem(count) abort
for i in range(a:count)
if !search(s:item_pattern, 'W') && getline('.') !~# s:item_pattern
@@ -2743,6 +2800,9 @@ function! s:PreviousSectionEnd(count) abort
endfunction
function! s:StageInline(mode, ...) abort
+ if &filetype !=# 'fugitive'
+ return ''
+ endif
let lnum1 = a:0 ? a:1 : line('.')
let lnum = lnum1 + 1
if a:0 > 1 && a:2 == 0
@@ -5017,8 +5077,14 @@ function! fugitive#MapJumps(...) abort
nnoremap <buffer> <silent> <C-N> :<C-U>execute <SID>NextItem(v:count1)<CR>
call s:MapEx('(', 'exe <SID>PreviousItem(v:count1)')
call s:MapEx(')', 'exe <SID>NextItem(v:count1)')
- call s:MapEx('K', 'exe <SID>PreviousItem(v:count1)')
- call s:MapEx('J', 'exe <SID>NextItem(v:count1)')
+ call s:MapEx('K', 'exe <SID>PreviousHunk(v:count1)')
+ call s:MapEx('J', 'exe <SID>NextHunk(v:count1)')
+ call s:MapEx('[c', 'exe <SID>PreviousHunk(v:count1)')
+ call s:MapEx(']c', 'exe <SID>NextHunk(v:count1)')
+ call s:MapEx('[/', 'exe <SID>PreviousFile(v:count1)')
+ call s:MapEx(']/', 'exe <SID>NextFile(v:count1)')
+ call s:MapEx('[m', 'exe <SID>PreviousFile(v:count1)')
+ call s:MapEx(']m', 'exe <SID>NextFile(v:count1)')
call s:MapEx('[[', 'exe <SID>PreviousSection(v:count1)')
call s:MapEx(']]', 'exe <SID>NextSection(v:count1)')
call s:MapEx('[]', 'exe <SID>PreviousSectionEnd(v:count1)')
diff --git a/doc/fugitive.txt b/doc/fugitive.txt
@@ -338,6 +338,26 @@ C Open the commit containing the current file.
*fugitive_CTRL-N* *fugitive_)*
) Jump to the next file, hunk, or revision.
+ *fugitive_[c*
+[c Jump to previous hunk, expanding inline diffs
+ automatically. (This shadows the Vim built-in |[c|
+ that provides a similar operation in |diff| mode.)
+
+ *fugitive_]c*
+]c Jump to next hunk, expanding inline diffs
+ automatically. (This shadows the Vim built-in |]c|
+ that provides a similar operation in |diff| mode.)
+
+ *fugitive_[/* *fugitive_[m*
+[/ Jump to previous file, collapsing inline diffs
+[m automatically. (Mnemonic: "/" appears in filenames,
+ "m" appears in "filenames".)
+
+ *fugitive_]/* *fugitive_]m*
+]/ Jump to next file, collapsing inline diffs
+]m automatically. (Mnemonic: "/" appears in filenames,
+ "m" appears in "filenames".)
+
*fugitive_i*
i Jump to the next file or hunk, expanding inline diffs
automatically.