简体   繁体   中英

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

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 ?

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, eg /usr/share/vim/vim70/ftplugin/gitcommit.vim , if you're curious to have a look!

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

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

Enjoy!

I highly recommend tpopes's vim-fugitive plugin for working with git.

You can find it here

I use Pierre Habouzit's git.vim from www.vim.org. Drop it into ~/.vim/ftplugin and you should be all set (assuming the usual filetype plugin indent on in your ~/.vimrc).

If you're using git 2.9 and above, you can get this behaviour by running git config --global commit.verbose true .

Source: this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM