dotfiles/nvim/.config/nvim/after/plugin/fugitive.vim

47 lines
2 KiB
VimL

nnoremap <Leader>ga :Git fetch --all<CR>
xnoremap <Leader>gb :Git blame<CR>
nnoremap <Leader>gb :Git branch -a<CR>
nnoremap <Leader>gB :Git branch<SPACE>
nnoremap <Leader>gc :Git checkout -b<SPACE>
nnoremap <Leader>gC :Git checkout<SPACE>
nnoremap <Leader>gd :Ghdiffsplit!<CR>
nnoremap <Leader>gD :Gvdiffsplit!<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>
nnoremap <Leader>gM :Git merge origin/
nnoremap <Leader>gp :Git push<CR>
nnoremap <Leader>gP :Git push -u<SPACE>
nnoremap <Leader>gr :Git rebase origin/master<CR>
nnoremap <Leader>gR :Git rebase origin/main<CR>
nnoremap <Leader>g- :Git stash<CR>:e<CR>
nnoremap <Leader>g+ :Git stash pop<CR>:e<CR>
nnoremap <Leader>gs :Git<CR>
nnoremap <Leader>gS :Git<SPACE>
nnoremap <Leader>gw :Gwrite<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