From e5a6a8c5256c8afe2c607f8566e4ef35c43b5de2 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 2 Aug 2019 17:07:27 -0400 Subject: [PATCH] Support jump maps in visual mode --- autoload/fugitive.vim | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index e0d007f..f6b0037 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1808,8 +1808,6 @@ function! fugitive#BufReadStatus() abort let nowait = v:version >= 704 ? '' : '' nunmap P nunmap ~ - nnoremap [[ :execute PreviousSection(v:count1) - nnoremap ]] :execute NextSection(v:count1) exe "nnoremap " nowait "- :execute Do('Toggle',0)" exe "xnoremap " nowait "- :execute Do('Toggle',1)" exe "nnoremap " nowait "s :execute Do('Stage',0)" @@ -1817,12 +1815,12 @@ function! fugitive#BufReadStatus() abort exe "nnoremap " nowait "u :execute Do('Unstage',0)" exe "xnoremap " nowait "u :execute Do('Unstage',1)" nnoremap U :exe EchoExec('reset', '-q') - nnoremap gu :exe StageJump(v:count, 'Unstaged') - nnoremap gU :exe StageJump(v:count, 'Untracked') - nnoremap gs :exe StageJump(v:count, 'Staged') - nnoremap gp :exe StageJump(v:count, 'Unpushed') - nnoremap gP :exe StageJump(v:count, 'Unpulled') - nnoremap gr :exe StageJump(v:count, 'Rebasing') + call s:MapEx('gu', "exe StageJump(v:count, 'Unstaged')") + call s:MapEx('gU', "exe StageJump(v:count, 'Untracked')") + call s:MapEx('gs', "exe StageJump(v:count, 'Staged')") + call s:MapEx('gp', "exe StageJump(v:count, 'Unpushed')") + call s:MapEx('gP', "exe StageJump(v:count, 'Unpulled')") + call s:MapEx('gr', "exe StageJump(v:count, 'Rebasing')") nnoremap C :Gcommit:echohl WarningMsgecho ':Gstatus C is deprecated in favor of cc'echohl NONE nnoremap a :execute Do('Toggle',0) nnoremap i :execute NextExpandedHunk(v:count1) @@ -4913,6 +4911,12 @@ function! s:NavigateUp(count) abort return rev endfunction +function! s:MapEx(lhs, rhs) abort + execute "nnoremap " s:nowait a:lhs ":" . a:rhs . "" + execute "onoremap " s:nowait a:lhs ":" . a:rhs . "" + execute "xnoremap " s:nowait a:lhs ":exe 'normal! gv'" . a:rhs . "" +endfunction + function! fugitive#MapJumps(...) abort if !&modifiable if get(b:, 'fugitive_type', '') ==# 'blob' @@ -4936,10 +4940,12 @@ function! fugitive#MapJumps(...) abort nnoremap :execute PreviousFileHunk(v:count1) endif nnoremap :execute NextFileHunk(v:count1) - nnoremap ( :execute PreviousFileHunk(v:count1) - nnoremap ) :execute NextFileHunk(v:count1) - nnoremap K :execute PreviousFileHunk(v:count1) - nnoremap J :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)') + call s:MapEx('[[', 'exe PreviousSection(v:count1)') + call s:MapEx(']]', 'exe NextSection(v:count1)') endif exe "nnoremap " s:nowait "- :exe 'Gedit ' . fnameescape(NavigateUp(v:count1)) if getline(1) =~# '^tree \x\{40,\}$' && empty(getline(2))call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')endif" nnoremap P :exe 'Gedit ' . fnameescape(ContainingCommit().'^'.v:count1.Relative(':')) @@ -4949,6 +4955,7 @@ function! fugitive#MapJumps(...) abort nnoremap gC :exe 'Gpedit ' . fnameescape(ContainingCommit()) nnoremap gc :exe 'Gpedit ' . fnameescape(ContainingCommit()) nnoremap gi :exe 'Gsplit' (v:count ? '.gitignore' : '.git/info/exclude') + xnoremap gi :exe 'Gsplit' (v:count ? '.gitignore' : '.git/info/exclude') nnoremap c :Gcommit nnoremap c :Gcommit