Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get git to display the changes in vim as hg does with the hgeditor script?

Tags:

git

vim

mercurial

An interesting feature in mercurial is the ability to view the changes that will be committed in a vim split (see DiffsInCommitMessageInVIM).

Any hint on how to do so with git ?

like image 230
Alexis Métaireau Avatar asked Jan 24 '11 17:01

Alexis Métaireau


People also ask

Can I use vim with git?

Git command works in the command line interface. The vim plugin named fugitive plugin is developed by Tim pope which is used to work with the git tool without terminating the editor. So, vim and git can work together by using the fugitive plugin.

What is the default editor in git?

On Windows, if you use Git Bash the default editor will be Vim. Vim is another text editor, like nano or notepad.

What is git commit verbose?

Using git commit --verbose This means that I don't need any plugins, and can remain in my $EDITOR , as well as it being a fully supported configuration by Git, by running git config --global commit.


2 Answers

Assuming you've got syntax enabled, Vim detects git commit messages as a filetype. This should be obvious from highlighting. The much less obvious part is that it also has a filetype plugin for git commits (and other git things). Make sure you have those enabled (filetype plugin on), and then there will be a helpful command defined: DiffGitCached. Just run that, and it'll toss a diff into a preview window.

A comment next to the definition of that command in the plugin:

Automatically diffing can be done with:

autocmd FileType gitcommit DiffGitCached | wincmd p

The filetype plugins are stored in /vimXX/ftplugin/git*.vim, e.g. /usr/share/vim/vim70/ftplugin/gitcommit.vim, if you're curious to have a look!

like image 71
Cascabel Avatar answered Sep 25 '22 16:09

Cascabel


I've modified the HGEDITOR.SH script to support Git, you can clone it here:

git clone git://github.com/dharrigan/giteditor.git

Enjoy!

like image 29
dharriagn Avatar answered Sep 24 '22 16:09

dharriagn