feat(vim): open git status in current tab
This commit is contained in:
@@ -103,7 +103,7 @@ nmap <Leader>gd :Gdiffsplit<CR>
|
|||||||
nmap <Leader>gc :G commit<CR>
|
nmap <Leader>gc :G commit<CR>
|
||||||
nmap <Leader>ga :G commit --amend<CR>
|
nmap <Leader>ga :G commit --amend<CR>
|
||||||
nmap <Leader>gp :G push<CR>
|
nmap <Leader>gp :G push<CR>
|
||||||
nmap <Leader>gg :tabnew \| leftabove vert G \| vert resize 50 \| set wfw<CR>
|
nmap <Leader>gg :call ToggleGitStatus()<CR>
|
||||||
nmap ]g <Plug>(GitGutterNextHunk)
|
nmap ]g <Plug>(GitGutterNextHunk)
|
||||||
nmap [g <Plug>(GitGutterPrevHunk)
|
nmap [g <Plug>(GitGutterPrevHunk)
|
||||||
map <Leader>gs <Plug>(GitGutterStageHunk)
|
map <Leader>gs <Plug>(GitGutterStageHunk)
|
||||||
@@ -611,4 +611,36 @@ function! s:SetupGitGutter()
|
|||||||
set statusline=%!StatusLine()
|
set statusline=%!StatusLine()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! OpenGitStatus()
|
||||||
|
let l:previous_win = win_getid()
|
||||||
|
echo l:previous_win
|
||||||
|
leftabove vertical G
|
||||||
|
vertical resize 50
|
||||||
|
setlocal winfixwidth
|
||||||
|
call win_gotoid(l:previous_win)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GetGitStatusWin()
|
||||||
|
let l:current_tabpage = tabpagenr()
|
||||||
|
for l:winnr in range(1, winnr('$'))
|
||||||
|
let l:bufnr = winbufnr(l:winnr)
|
||||||
|
let l:buftype = getbufvar(l:bufnr, '&buftype')
|
||||||
|
let l:bufname = bufname(l:bufnr)
|
||||||
|
if l:buftype ==# 'nowrite' && l:bufname =~# '^fugitive://.*\.git//$'
|
||||||
|
return l:winnr
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ToggleGitStatus()
|
||||||
|
let l:win = GetGitStatusWin()
|
||||||
|
if l:win
|
||||||
|
execute l:win . 'wincmd c'
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
call OpenGitStatus()
|
||||||
|
endfunction
|
||||||
|
|
||||||
autocmd VimEnter * call s:SetupGitGutter()
|
autocmd VimEnter * call s:SetupGitGutter()
|
||||||
|
|||||||
Reference in New Issue
Block a user