開啟後自動 resize 到作者名
:Gblame 打開後,預設會顯示到 Date,很佔畫面,按 A 可以縮到 Author。
煩的是沒有選項能自動這件事,只好另設一個 command,在 :Gblame 後多送一個 A
command! -nargs=0 GBlameA Gblame | call <SID>fugitiveblame_after()
function! s:fugitiveblame_after()
call feedkeys('A')
endfunction
然後用 tyru/vim-altercmd 方便輸入……
AlterCommand gb[lame] GBlameA
很微小的修改,原本狀態列會顯示 fugitive tmp file 的名稱,我把它改成 "Gblame"。
function! AirlineGblame(...)
if &filetype == 'fugitiveblame'
let w:airline_section_a = ''
let w:airline_section_b = ''
let w:airline_section_c = 'Gblame'
let w:airline_section_y = ''
endif
endfunction
let g:airline_statusline_funcrefs = []
call airline#add_statusline_func('AirlineGblame')
Git compare
配合 bootleq/vim-gitdiffall 使用,
按 gf 將檔案變更以 vim diff 開在新 tab,看那個 revision 改了什麼:
按 <LocalLeader>gf 則是開啟新的 tmux window,把該版本變更的檔案全部打開:
function! s:fugitiveblame_gitdiffall(all)
let rev = matchstr(getline('.'), '\v^\w{7}')
let buffer = fugitive#buffer(bufname(b:fugitive_blamed_bufnr))
if a:all
call TmuxNewWindow({
\ "text": "gitdiffall @" . rev,
\ "title": '⎇',
\ "directory": buffer.repo().tree()
\ })
else
execute printf("tabnew %s | silent GitDiff @%s", buffer.path(), rev)
endif
endfunction
autocmd! my_vimrc FileType fugitiveblame
\ nnoremap <buffer> gf :call <SID>fugitiveblame_gitdiffall(0)<CR> |
\ nnoremap <buffer> <LocalLeader>gf :call <SID>fugitiveblame_gitdiffall(1)<CR>
function! TmuxNewWindow(...)
let options = a:0 ? a:1 : {}
let text = get(options, 'text', '')
let title = get(options, 'title', '')
let directory = get(options, 'directory', getcwd())
let cmd = 'tmux new-window -a '
\ . (empty(title) ? '' : printf('-n %s', shellescape(title)))
\ . printf(' -c %s', shellescape(directory))
call system(cmd)
if !empty(text)
let cmd = printf('tmux set-buffer %s \; paste-buffer -d \; send-keys Enter', shellescape(text))
call system(cmd)
endif
endfunction
這裡比較悶的是 Gblame 的 mapping 都寫死死,最後只好選 gf 來用。
看 issue 感覺是 tpope 不大想理 mapping 的彈性。