From bcfd9372dc8071c46aea75445c0232a672cc115c Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Wed, 27 Nov 2024 11:56:05 +0530 Subject: [PATCH] nvim: fugitive: Add mapping to view file on another branch --- nvim/.config/nvim/after/plugin/fugitive.vim | 1 + nvim/.config/nvim/autoload/git.vim | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/nvim/.config/nvim/after/plugin/fugitive.vim b/nvim/.config/nvim/after/plugin/fugitive.vim index d5f9fcb..ead892c 100644 --- a/nvim/.config/nvim/after/plugin/fugitive.vim +++ b/nvim/.config/nvim/after/plugin/fugitive.vim @@ -36,6 +36,7 @@ nnoremap G :keepalt Git nnoremap gp :call git#git_push_to_upstream() nnoremap gP git#git_push() +nnoremap gO git#git_show_file_on_branch() augroup custom_fugitive autocmd! diff --git a/nvim/.config/nvim/autoload/git.vim b/nvim/.config/nvim/autoload/git.vim index 8f03ec3..5f53436 100644 --- a/nvim/.config/nvim/autoload/git.vim +++ b/nvim/.config/nvim/autoload/git.vim @@ -289,6 +289,11 @@ function! git#git_review_fileview() abort execute "Git difftool -y " . default[3] . "..." . current endfunction +" Show file on another branch without changing current branch +function! git#git_show_file_on_branch() abort + return ":Git show :" . expand("%") +endfunction + " Generate a helpful name when using Git stash function! git#git_stash() abort let current = trim(system("git branch --show-current"))