From 91be84b9d7efe98f5c87611f05f1f81f14aec9de Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 1 Feb 2021 12:17:23 +0530 Subject: [PATCH] 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. --- nvim/.config/nvim/after/ftplugin/git.vim | 2 + nvim/.config/nvim/after/plugin/fugitive.vim | 44 ++++++ nvim/.config/nvim/after/plugin/gina.vim | 145 -------------------- nvim/.config/nvim/lua/plugins.lua | 2 +- 4 files changed, 47 insertions(+), 146 deletions(-) create mode 100644 nvim/.config/nvim/after/ftplugin/git.vim create mode 100644 nvim/.config/nvim/after/plugin/fugitive.vim delete mode 100644 nvim/.config/nvim/after/plugin/gina.vim diff --git a/nvim/.config/nvim/after/ftplugin/git.vim b/nvim/.config/nvim/after/ftplugin/git.vim new file mode 100644 index 0000000..a66e703 --- /dev/null +++ b/nvim/.config/nvim/after/ftplugin/git.vim @@ -0,0 +1,2 @@ +" Disable whitespace highlighting in git buffer +autocmd BufEnter DisableWhitespace diff --git a/nvim/.config/nvim/after/plugin/fugitive.vim b/nvim/.config/nvim/after/plugin/fugitive.vim new file mode 100644 index 0000000..cd54d0d --- /dev/null +++ b/nvim/.config/nvim/after/plugin/fugitive.vim @@ -0,0 +1,44 @@ +nnoremap ga :Git fetch --all +xnoremap gb :Git blame +nnoremap gd :Ghdiffsplit! +nnoremap gD :Gvdiffsplit! +nnoremap gs :Git +nnoremap gS :Git +nnoremap gc :Git commit -v -q +nnoremap gC :Git commit -v -q %:p +nnoremap gp :Git push +nnoremap gP :Git push -u +nnoremap g- :Git stash:e +nnoremap g+ :Git stash pop:e +nnoremap gw :Gwrite +nnoremap gM :0,3Git blame +nnoremap gr :Git rebase origin/master +nnoremap gR :Git rebase upstream/master +nnoremap gl :Git log % +nnoremap gL :Git log -n 100 +xnoremap gl :call git_log_range() +xnoremap gL :call git_log_named_block() + +" For 3 way merge +nnoremap dl :diffget //2 +nnoremap dr :diffget //3 + +" 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! `y + silent execute "Git log --no-patch -L :" . shellescape(@@) . ":%" +endfunction diff --git a/nvim/.config/nvim/after/plugin/gina.vim b/nvim/.config/nvim/after/plugin/gina.vim deleted file mode 100644 index 9ca21d5..0000000 --- a/nvim/.config/nvim/after/plugin/gina.vim +++ /dev/null @@ -1,145 +0,0 @@ -" Required for opening buffers vertically with gina-patch -set diffopt+=vertical - -nnoremap ga :Gina add %:p -nnoremap gb :Gina branch -nnoremap gB :Gina branch -a -nnoremap gc :Gina commit -nnoremap gC :Gina checkout -b -nnoremap gd :Gina diff -- % -nnoremap gD :Gina diff -nnoremap gf :Gina fetch --all -nnoremap gg :Gina -nnoremap gh :Gina patch -nnoremap gl :Gina log :% -nnoremap gL :Gina log -nnoremap gM :Gina merge -nnoremap gp :Gina push -nnoremap gP :Gina push --force-with-lease -nnoremap gr :Gina rebase origin/master -nnoremap gR :Gina remote -v -nnoremap gs :Gina status -nnoremap gt :Gina tag -nnoremap gT :Gina tag -nnoremap gu :Gina push -u -nnoremap g- :Gina stash:e -nnoremap g+ :Gina stash pop:e - -" 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', - \ ':call gina#action#call(''branch:delete'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'branch', 'br', - \ ':call gina#action#call(''branch:move:force'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'branch', 'su', - \ ':call gina#action#call(''branch:set-upstream-to'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'branch', 'uu', - \ ':call gina#action#call(''branch:unset-upstream'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'commit', 'gs', - \ ':Gina status', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'status', 'cc', - \ ':Gina commit', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ 'status', 'ga', - \ ':call gina#action#call(''add'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ '/\%(branch\|log\)', 'co', - \ ':call gina#action#call(''commit:checkout'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ '/\%(branch\|tag\)', 'ct', - \ ':call gina#action#call(''commit:checkout:track'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ '/\%(blame\|log\|reflog\)', - \ 'p', - \ ':call gina#action#call(''preview'')', - \ {'noremap': 1, 'silent': 1} - \) -call gina#custom#mapping#nmap( - \ '/\%(blame\|log\|reflog\)', - \ 'c', - \ ':call gina#action#call(''changes'')', - \ {'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', - \) diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 42c1d90..e4bb781 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -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'