From ff7e6f524c7992fb319422c2a1be118936d59f76 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Fri, 19 Mar 2021 12:11:37 +0530 Subject: [PATCH] nvim: git/fugitive: Add helper for git branch and checkout --- nvim/.config/nvim/after/ftplugin/git.vim | 9 +++++++++ nvim/.config/nvim/after/plugin/fugitive.vim | 2 ++ 2 files changed, 11 insertions(+) diff --git a/nvim/.config/nvim/after/ftplugin/git.vim b/nvim/.config/nvim/after/ftplugin/git.vim index a66e703..5eea627 100644 --- a/nvim/.config/nvim/after/ftplugin/git.vim +++ b/nvim/.config/nvim/after/ftplugin/git.vim @@ -1,2 +1,11 @@ " Disable whitespace highlighting in git buffer autocmd BufEnter DisableWhitespace + +xnoremap gb :call git_checkout_branch() + +" We would like to checkout a branch by visually selecting a branch name in +" the output of git branch -a. +function! s:git_checkout_branch() abort + normal! `y + silent execute "Git checkout " . shellescape(@@) +endfunction diff --git a/nvim/.config/nvim/after/plugin/fugitive.vim b/nvim/.config/nvim/after/plugin/fugitive.vim index cd54d0d..62b1c0e 100644 --- a/nvim/.config/nvim/after/plugin/fugitive.vim +++ b/nvim/.config/nvim/after/plugin/fugitive.vim @@ -1,5 +1,7 @@ nnoremap ga :Git fetch --all xnoremap gb :Git blame +nnoremap gb :Git branch +nnoremap gB :Git checkout -b nnoremap gd :Ghdiffsplit! nnoremap gD :Gvdiffsplit! nnoremap gs :Git