View different branch file inside VIM
Vim

View different branch file inside VIM

Jan 30, 2023  •  1 min read

Table of Contents

Over the past few months, VIM has become my goto text editor at both the workplace and at home. I still use Visual Studio Code when I want to inspect the project from a bird's eye view. There will come a time when you will want to view the contents of the same file or a different file from another branch. This could be for comparing the changes or just for checking the contents of another file. Note that I am not an advanced Git user.

In VIM, there is a plugin named vim-fugitive for performing Git operations from within the editor. Refer to its docs for its usage and commands.

Commands

To inspect the contents of a file for a supplied path

:Gvsplit branch_name:path_of_file

To view the contents of the same file as the working file

:Gvsplit branch_name:%

To compare files

:Gvdiffsplit branch_name:%

Explanation