diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index f6b0037..28bd9dc 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2236,7 +2236,7 @@ function! s:StageJump(offset, section, ...) abort let line = search('^' . a:section, 'nw') if line exe line - return s:NextFileHunk(a:offset ? a:offset : 1) + return s:NextItem(a:offset ? a:offset : 1) endif return '' endfunction @@ -2622,23 +2622,36 @@ function! s:StageReveal(...) abort while getline(end) =~# '^[ \+-]' let end += 1 endwhile + elseif getline(begin) =~# '^commit ' + let end = begin + while end < line('$') && getline(end + 1) !~# '^commit ' + let end += 1 + endwhile + endif + if exists('end') while line('w$') < line('$') && end > line('w$') && line('.') > line('w0') + &scrolloff execute "normal! \" endwhile endif endfunction -function! s:NextFileHunk(count) abort +let s:item_pattern = '^[A-Z?] .\|^diff --\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@' + +function! s:NextItem(count) abort for i in range(a:count) - call search('^[A-Z?] .\|^diff --\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@','W') + if !search(s:item_pattern, 'W') && getline('.') !~# s:item_pattern + call search('^commit ', 'W') + endif endfor call s:StageReveal() return '.' endfunction -function! s:PreviousFileHunk(count) abort +function! s:PreviousItem(count) abort for i in range(a:count) - call search('^[A-Z?] .\|^diff --\|^[0-9a-f]\{4,\} \|^@','Wbe') + if !search(s:item_pattern, 'Wbe') && getline('.') !~# s:item_pattern + call search('^commit ', 'Wbe') + endif endfor call s:StageReveal() return '.' @@ -4935,15 +4948,15 @@ function! fugitive#MapJumps(...) abort nnoremap p :exe GF("pedit") if exists(':CtrlP') && get(g:, 'ctrl_p_map') =~? '^$' - nnoremap :execute line('.') == 1 ? 'CtrlP ' . fnameescape(Tree()) : PreviousFileHunk(v:count1) + nnoremap :execute line('.') == 1 ? 'CtrlP ' . fnameescape(Tree()) : PreviousItem(v:count1) else - nnoremap :execute PreviousFileHunk(v:count1) + nnoremap :execute PreviousItem(v:count1) endif - nnoremap :execute NextFileHunk(v:count1) - call s:MapEx('(', 'exe PreviousFileHunk(v:count1)') - call s:MapEx(')', 'exe NextFileHunk(v:count1)') - call s:MapEx('K', 'exe PreviousFileHunk(v:count1)') - call s:MapEx('J', 'exe NextFileHunk(v:count1)') + nnoremap :execute NextItem(v:count1) + call s:MapEx('(', 'exe PreviousItem(v:count1)') + call s:MapEx(')', 'exe NextItem(v:count1)') + call s:MapEx('K', 'exe PreviousItem(v:count1)') + call s:MapEx('J', 'exe NextItem(v:count1)') call s:MapEx('[[', 'exe PreviousSection(v:count1)') call s:MapEx(']]', 'exe NextSection(v:count1)') endif diff --git a/doc/fugitive.txt b/doc/fugitive.txt index fa976d5..ee1ad20 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -333,12 +333,10 @@ P Open the current file in the [count]th parent. C Open the commit containing the current file. *fugitive_CTRL-P* *fugitive_(* -( Jump to the previous file or hunk. - +( Jump to the previous file, hunk, or revision. *fugitive_CTRL-N* *fugitive_)* -) Jump to the next file or hunk. - +) Jump to the next file, hunk, or revision. *fugitive_i* i Jump to the next file or hunk, expanding inline diffs