Provide separate file/hunk jump maps

This commit is contained in:
Tim Pope 2019-08-03 00:52:49 -04:00
parent 35cf80dd3b
commit 0f08b0cbbb
2 changed files with 88 additions and 2 deletions

View File

@ -2654,6 +2654,63 @@ endfunction
let s:file_pattern = '^[A-Z?] .\|^diff --' let s:file_pattern = '^[A-Z?] .\|^diff --'
let s:item_pattern = s:file_pattern . '\|^\%(\l\{3,\} \)\=[0-9a-f]\{4,\} \|^@@' 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 function! s:NextItem(count) abort
for i in range(a:count) for i in range(a:count)
if !search(s:item_pattern, 'W') && getline('.') !~# s:item_pattern if !search(s:item_pattern, 'W') && getline('.') !~# s:item_pattern
@ -2743,6 +2800,9 @@ function! s:PreviousSectionEnd(count) abort
endfunction endfunction
function! s:StageInline(mode, ...) abort function! s:StageInline(mode, ...) abort
if &filetype !=# 'fugitive'
return ''
endif
let lnum1 = a:0 ? a:1 : line('.') let lnum1 = a:0 ? a:1 : line('.')
let lnum = lnum1 + 1 let lnum = lnum1 + 1
if a:0 > 1 && a:2 == 0 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> 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>PreviousItem(v:count1)')
call s:MapEx(')', 'exe <SID>NextItem(v:count1)') call s:MapEx(')', 'exe <SID>NextItem(v:count1)')
call s:MapEx('K', 'exe <SID>PreviousItem(v:count1)') call s:MapEx('K', 'exe <SID>PreviousHunk(v:count1)')
call s:MapEx('J', 'exe <SID>NextItem(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>PreviousSection(v:count1)')
call s:MapEx(']]', 'exe <SID>NextSection(v:count1)') call s:MapEx(']]', 'exe <SID>NextSection(v:count1)')
call s:MapEx('[]', 'exe <SID>PreviousSectionEnd(v:count1)') call s:MapEx('[]', 'exe <SID>PreviousSectionEnd(v:count1)')

View File

@ -338,6 +338,26 @@ C Open the commit containing the current file.
*fugitive_CTRL-N* *fugitive_)* *fugitive_CTRL-N* *fugitive_)*
) Jump to the next file, hunk, or revision. ) 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* *fugitive_i*
i Jump to the next file or hunk, expanding inline diffs i Jump to the next file or hunk, expanding inline diffs
automatically. automatically.