diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 24b6cf5..ec19337 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2664,6 +2664,55 @@ let s:rebase_abbrevs = { \ 'b': 'break', \ } +function! s:MapStatus() abort + call fugitive#MapJumps() + call s:Map('n', '-', ":execute Do('Toggle',0)", '') + call s:Map('x', '-', ":execute Do('Toggle',1)", '') + call s:Map('n', 's', ":execute Do('Stage',0)", '') + call s:Map('x', 's', ":execute Do('Stage',1)", '') + call s:Map('n', 'u', ":execute Do('Unstage',0)", '') + call s:Map('x', 'u', ":execute Do('Unstage',1)", '') + call s:Map('n', 'U', ":Git reset -q", '') + call s:MapMotion('gu', "exe StageJump(v:count, 'Untracked', 'Unstaged')") + call s:MapMotion('gU', "exe StageJump(v:count, 'Unstaged', 'Untracked')") + call s:MapMotion('gs', "exe StageJump(v:count, 'Staged')") + call s:MapMotion('gp', "exe StageJump(v:count, 'Unpushed')") + call s:MapMotion('gP', "exe StageJump(v:count, 'Unpulled')") + call s:MapMotion('gr', "exe StageJump(v:count, 'Rebasing')") + call s:Map('n', 'C', ":echoerr 'fugitive: C has been removed in favor of cc'", '') + call s:Map('n', 'a', ":execute Do('Toggle',0)", '') + call s:Map('n', 'i', ":execute NextExpandedHunk(v:count1)", '') + call s:Map('n', "=", ":execute StageInline('toggle',line('.'),v:count)", '') + call s:Map('n', "<", ":execute StageInline('hide', line('.'),v:count)", '') + call s:Map('n', ">", ":execute StageInline('show', line('.'),v:count)", '') + call s:Map('x', "=", ":execute StageInline('toggle',line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') + call s:Map('x', "<", ":execute StageInline('hide', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') + call s:Map('x', ">", ":execute StageInline('show', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') + call s:Map('n', 'D', ":echoerr 'fugitive: D has been removed in favor of dd'", '') + call s:Map('n', 'dd', ":execute StageDiff('Gdiffsplit')", '') + call s:Map('n', 'dh', ":execute StageDiff('Ghdiffsplit')", '') + call s:Map('n', 'ds', ":execute StageDiff('Ghdiffsplit')", '') + call s:Map('n', 'dp', ":execute StageDiffEdit()", '') + call s:Map('n', 'dv', ":execute StageDiff('Gvdiffsplit')", '') + call s:Map('n', 'd?', ":help fugitive_d", '') + call s:Map('n', 'P', ":execute StagePatch(line('.'),line('.')+v:count1-1)", '') + call s:Map('x', 'P', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') + call s:Map('n', 'p', ":if v:countsilent exe GF('pedit')elseechoerr 'Use = for inline diff, P for :Git add/reset --patch, 1p for :pedit'endif", '') + call s:Map('x', 'p', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') + call s:Map('n', 'I', ":execute StagePatch(line('.'),line('.'))", '') + call s:Map('x', 'I', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') + call s:Map('n', 'gq', ":if bufnr('$') == 1quitelsebdeleteendif", '') + call s:Map('n', 'R', ":echohl WarningMsgecho 'Reloading is automatic. Use :e to force'echohl NONE", '') + call s:Map('n', 'g', ":echoerr 'Changed to X'", '') + call s:Map('x', 'g', ":echoerr 'Changed to X'", '') + call s:Map('n', 'X', ":execute StageDelete(line('.'), 0, v:count)", '') + call s:Map('x', 'X', ":execute StageDelete(line(\"'<\"), line(\"'>\"), v:count)", '') + call s:Map('n', 'gI', ":execute StageIgnore(line('.'), line('.'), v:count)", '') + call s:Map('x', 'gI', ":execute StageIgnore(line(\"'<\"), line(\"'>\"), v:count)", '') + call s:Map('n', '.', ': =StageArgs(0)') + call s:Map('x', '.', ': =StageArgs(1)') +endfunction + function! fugitive#BufReadStatus(cmdbang) abort let amatch = s:Slash(expand('%:p')) if a:cmdbang @@ -2690,8 +2739,10 @@ function! fugitive#BufReadStatus(cmdbang) abort let status = fugitive#Execute(status_cmd, function('len')) endif - doautocmd BufReadPre - setlocal noreadonly modifiable nomodeline buftype=nowrite + doautocmd BufReadPre + + setlocal readonly nomodifiable noswapfile nomodeline buftype=nowrite + call s:MapStatus() let [staged, unstaged, untracked] = [[], [], []] let props = {} @@ -2910,6 +2961,7 @@ function! fugitive#BufReadStatus(cmdbang) abort let expanded = get(b:, 'fugitive_expanded', {'Staged': {}, 'Unstaged': {}}) let b:fugitive_expanded = {'Staged': {}, 'Unstaged': {}} + setlocal noreadonly modifiable silent keepjumps %delete_ call s:AddHeader('Head', head) @@ -2959,63 +3011,7 @@ function! fugitive#BufReadStatus(cmdbang) abort call s:AddLogSection('Unpulled from ' . pull_short, s:QueryLogRange(head, pull_ref, dir)) endif - setlocal nomodified readonly noswapfile - doautocmd BufReadPost - setlocal nomodifiable - if &bufhidden ==# '' - setlocal bufhidden=delete - endif - if !exists('b:dispatch') - let b:dispatch = ':Git fetch --all' - endif - call fugitive#MapJumps() - call s:Map('n', '-', ":execute Do('Toggle',0)", '') - call s:Map('x', '-', ":execute Do('Toggle',1)", '') - call s:Map('n', 's', ":execute Do('Stage',0)", '') - call s:Map('x', 's', ":execute Do('Stage',1)", '') - call s:Map('n', 'u', ":execute Do('Unstage',0)", '') - call s:Map('x', 'u', ":execute Do('Unstage',1)", '') - call s:Map('n', 'U', ":Git reset -q", '') - call s:MapMotion('gu', "exe StageJump(v:count, 'Untracked', 'Unstaged')") - call s:MapMotion('gU', "exe StageJump(v:count, 'Unstaged', 'Untracked')") - call s:MapMotion('gs', "exe StageJump(v:count, 'Staged')") - call s:MapMotion('gp', "exe StageJump(v:count, 'Unpushed')") - call s:MapMotion('gP', "exe StageJump(v:count, 'Unpulled')") - call s:MapMotion('gr', "exe StageJump(v:count, 'Rebasing')") - call s:Map('n', 'C', ":echoerr 'fugitive: C has been removed in favor of cc'", '') - call s:Map('n', 'a', ":execute Do('Toggle',0)", '') - call s:Map('n', 'i', ":execute NextExpandedHunk(v:count1)", '') - call s:Map('n', "=", ":execute StageInline('toggle',line('.'),v:count)", '') - call s:Map('n', "<", ":execute StageInline('hide', line('.'),v:count)", '') - call s:Map('n', ">", ":execute StageInline('show', line('.'),v:count)", '') - call s:Map('x', "=", ":execute StageInline('toggle',line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') - call s:Map('x', "<", ":execute StageInline('hide', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') - call s:Map('x', ">", ":execute StageInline('show', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)", '') - call s:Map('n', 'D', ":echoerr 'fugitive: D has been removed in favor of dd'", '') - call s:Map('n', 'dd', ":execute StageDiff('Gdiffsplit')", '') - call s:Map('n', 'dh', ":execute StageDiff('Ghdiffsplit')", '') - call s:Map('n', 'ds', ":execute StageDiff('Ghdiffsplit')", '') - call s:Map('n', 'dp', ":execute StageDiffEdit()", '') - call s:Map('n', 'dv', ":execute StageDiff('Gvdiffsplit')", '') - call s:Map('n', 'd?', ":help fugitive_d", '') - call s:Map('n', 'P', ":execute StagePatch(line('.'),line('.')+v:count1-1)", '') - call s:Map('x', 'P', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') - call s:Map('n', 'p', ":if v:countsilent exe GF('pedit')elseechoerr 'Use = for inline diff, P for :Git add/reset --patch, 1p for :pedit'endif", '') - call s:Map('x', 'p', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') - call s:Map('n', 'I', ":execute StagePatch(line('.'),line('.'))", '') - call s:Map('x', 'I', ":execute StagePatch(line(\"'<\"),line(\"'>\"))", '') - call s:Map('n', 'gq', ":if bufnr('$') == 1quitelsebdeleteendif", '') - call s:Map('n', 'R', ":echohl WarningMsgecho 'Reloading is automatic. Use :e to force'echohl NONE", '') - call s:Map('n', 'g', ":echoerr 'Changed to X'", '') - call s:Map('x', 'g', ":echoerr 'Changed to X'", '') - call s:Map('n', 'X', ":execute StageDelete(line('.'), 0, v:count)", '') - call s:Map('x', 'X', ":execute StageDelete(line(\"'<\"), line(\"'>\"), v:count)", '') - call s:Map('n', 'gI', ":execute StageIgnore(line('.'), line('.'), v:count)", '') - call s:Map('x', 'gI', ":execute StageIgnore(line(\"'<\"), line(\"'>\"), v:count)", '') - call s:Map('n', '.', ': =StageArgs(0)') - call s:Map('x', '.', ': =StageArgs(1)') - setlocal filetype=fugitive - + setlocal nomodified readonly nomodifiable for [lnum, section] in [[staged_end, 'Staged'], [unstaged_end, 'Unstaged']] while len(getline(lnum)) let filename = matchstr(getline(lnum), '^[A-Z?] \zs.*') @@ -3026,6 +3022,15 @@ function! fugitive#BufReadStatus(cmdbang) abort endwhile endfor + doautocmd BufReadPost + if &bufhidden ==# '' + setlocal bufhidden=delete + endif + if !exists('b:dispatch') + let b:dispatch = ':Git fetch --all' + endif + setlocal filetype=fugitive + let b:fugitive_reltime = reltime() return s:DoAutocmd('User FugitiveIndex') catch /^fugitive:/