nvim: Switch back to fugitive again :)

With most of our operations now being done through fzf + git command
line or lazygit, we primarily only require the log & blame facilities.
The blame interface in Gina is confusing.

This time however, we include some nice helper functions of our own.
This commit is contained in:
Sanchayan Maity 2021-02-01 12:17:23 +05:30
parent a23caf6d12
commit 91be84b9d7
4 changed files with 47 additions and 146 deletions

View File

@ -0,0 +1,2 @@
" Disable whitespace highlighting in git buffer
autocmd BufEnter <buffer> DisableWhitespace

View File

@ -0,0 +1,44 @@
nnoremap <Leader>ga :Git fetch --all<CR>
xnoremap <Leader>gb :Git blame<CR>
nnoremap <Leader>gd :Ghdiffsplit!<CR>
nnoremap <Leader>gD :Gvdiffsplit!<CR>
nnoremap <Leader>gs :Git<CR>
nnoremap <Leader>gS :Git<SPACE>
nnoremap <Leader>gc :Git commit -v -q<CR>
nnoremap <Leader>gC :Git commit -v -q %:p<CR>
nnoremap <Leader>gp :Git push<CR>
nnoremap <Leader>gP :Git push -u<SPACE>
nnoremap <Leader>g- :Git stash<CR>:e<CR>
nnoremap <Leader>g+ :Git stash pop<CR>:e<CR>
nnoremap <Leader>gw :Gwrite<CR>
nnoremap <Leader>gM :0,3Git blame<CR>
nnoremap <Leader>gr :Git rebase origin/master<CR>
nnoremap <Leader>gR :Git rebase upstream/master<CR>
nnoremap <Leader>gl :Git log %<CR>
nnoremap <Leader>gL :Git log -n 100<CR>
xnoremap <Leader>gl :<C-U>call <SID>git_log_range()<CR>
xnoremap <Leader>gL :<C-U>call <SID>git_log_named_block()<CR>
" For 3 way merge
nnoremap <Leader>dl :diffget //2<CR>
nnoremap <Leader>dr :diffget //3<CR>
" The next two functions allow scoping diffs by line range of a file and named
" block in a file. Inspired by reading the following article.
" https://susanpotter.net/software/tracking-diffs-by-scoping-to-file-range-function-method-or-class-changes-in-git/
" Use these two links as reference to come up with this function
" https://vi.stackexchange.com/questions/17606/vmap-and-visual-block-how-do-i-write-a-function-to-operate-once-for-the-entire
" https://stackoverflow.com/questions/41238238/how-to-map-vim-visual-mode-to-replace-my-selected-text-parts
function! s:git_log_range() abort
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
silent execute "Git log --no-patch -L " . lnum1 . "," . lnum2 . ":%"
endfunction
" Taken from https://learnvimscriptthehardway.stevelosh.com/chapters/33.html.
" Modified and stripped to do what I needed.
function! s:git_log_named_block() abort
normal! `<v`>y
silent execute "Git log --no-patch -L :" . shellescape(@@) . ":%"
endfunction

View File

@ -1,145 +0,0 @@
" Required for opening buffers vertically with gina-patch
set diffopt+=vertical
nnoremap <Leader>ga :Gina add %:p<CR>
nnoremap <Leader>gb :Gina branch<CR>
nnoremap <Leader>gB :Gina branch -a<CR>
nnoremap <Leader>gc :Gina commit<CR>
nnoremap <Leader>gC :Gina checkout -b<SPACE>
nnoremap <Leader>gd :Gina diff -- %<CR>
nnoremap <Leader>gD :Gina diff<CR>
nnoremap <Leader>gf :Gina fetch --all<CR>
nnoremap <Leader>gg :Gina<SPACE>
nnoremap <Leader>gh :Gina patch<CR>
nnoremap <Leader>gl :Gina log :%<CR>
nnoremap <Leader>gL :Gina log<CR>
nnoremap <Leader>gM :Gina merge<SPACE>
nnoremap <Leader>gp :Gina push<CR>
nnoremap <Leader>gP :Gina push --force-with-lease<CR>
nnoremap <Leader>gr :Gina rebase origin/master<CR>
nnoremap <Leader>gR :Gina remote -v<CR>
nnoremap <Leader>gs :Gina status<CR>
nnoremap <Leader>gt :Gina tag<CR>
nnoremap <Leader>gT :Gina tag<SPACE>
nnoremap <Leader>gu :Gina push -u<SPACE>
nnoremap <Leader>g- :Gina stash<CR>:e<CR>
nnoremap <Leader>g+ :Gina stash pop<CR>:e<CR>
" Default options for the specific git commands
call gina#custom#command#option(
\ 'commit', '-v|--verbose'
\)
call gina#custom#command#option(
\ 'patch', '--oneside'
\)
call gina#custom#command#option(
\ 'patch',
\ '--opener', 'split'
\)
call gina#custom#command#option(
\ 'show',
\ '--opener', 'split',
\ '--show-signature'
\)
call gina#custom#command#option(
\ '/\%(status\|commit\)',
\ '-u|--untracked-files'
\)
call gina#custom#command#option(
\ 'status',
\ '-b|--branch'
\)
call gina#custom#command#option(
\ '/\%(branch\|commit\|diff\|log\|status\|tag\)',
\ '--opener', 'split'
\)
" Custom action aliases for gina buffers
call gina#custom#action#alias(
\ '/\%(blame\|log\|reflog\)',
\ 'preview',
\ 'belowright show:commit:preview',
\)
call gina#custom#action#alias(
\ '/\%(blame\|log\|reflog\)',
\ 'changes',
\ 'belowright changes:of:preview',
\)
" Custom key bindings in gina buffers
call gina#custom#mapping#nmap(
\ 'branch', 'bd',
\ ':<C-u>call gina#action#call(''branch:delete'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'branch', 'br',
\ ':<C-u>call gina#action#call(''branch:move:force'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'branch', 'su',
\ ':<c-u>call gina#action#call(''branch:set-upstream-to'')<cr>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'branch', 'uu',
\ ':<c-u>call gina#action#call(''branch:unset-upstream'')<cr>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'commit', 'gs',
\ ':<C-u>Gina status<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'status', 'cc',
\ ':<C-u>Gina commit<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ 'status', 'ga',
\ ':<C-u>call gina#action#call(''add'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ '/\%(branch\|log\)', 'co',
\ ':<C-u>call gina#action#call(''commit:checkout'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ '/\%(branch\|tag\)', 'ct',
\ ':<C-u>call gina#action#call(''commit:checkout:track'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ '/\%(blame\|log\|reflog\)',
\ 'p',
\ ':<C-u>call gina#action#call(''preview'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
call gina#custom#mapping#nmap(
\ '/\%(blame\|log\|reflog\)',
\ 'c',
\ ':<C-u>call gina#action#call(''changes'')<CR>',
\ {'noremap': 1, 'silent': 1}
\)
" Set options for gina buffers
call gina#custom#execute(
\ '/\%(ls\|log\|reflog\|grep\)',
\ 'setlocal noautoread',
\)
call gina#custom#execute(
\ '/\%(status\|branch\|ls\|log\|reflog\|grep\)',
\ 'setlocal cursorline',
\)
call gina#custom#execute(
\ 'commit',
\ 'setlocal spell',
\)
call gina#custom#execute(
\ 'commit',
\ 'setlocal textwidth=72',
\)
call gina#custom#execute(
\ 'log',
\ 'setlocal number',
\)

View File

@ -45,7 +45,7 @@ local init = function ()
'mhinz/vim-signify',
config = "require('modules.signify')"
}
use 'lambdalisue/gina.vim'
use 'tpope/vim-fugitive'
use 'rhysd/git-messenger.vim'
use 'rhysd/conflict-marker.vim'
use 'salcode/vim-interactive-rebase-reverse'