diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 424ca08..d171a17 100644 --- 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 :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('K', 'exe PreviousHunk(v:count1)') + call s:MapEx('J', 'exe NextHunk(v:count1)') + call s:MapEx('[c', 'exe PreviousHunk(v:count1)') + call s:MapEx(']c', 'exe NextHunk(v:count1)') + call s:MapEx('[/', 'exe PreviousFile(v:count1)') + call s:MapEx(']/', 'exe NextFile(v:count1)') + call s:MapEx('[m', 'exe PreviousFile(v:count1)') + call s:MapEx(']m', 'exe NextFile(v:count1)') call s:MapEx('[[', 'exe PreviousSection(v:count1)') call s:MapEx(']]', 'exe NextSection(v:count1)') call s:MapEx('[]', 'exe PreviousSectionEnd(v:count1)') diff --git a/doc/fugitive.txt b/doc/fugitive.txt index fbc9371..8de7be4 100644 --- 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.