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

笑着哭i 提交于 2020-01-01 03:24:07

问题


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 ?


回答1:


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!




回答2:


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

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

Enjoy!




回答3:


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

You can find it here




回答4:


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).




回答5:


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.



来源:https://stackoverflow.com/questions/4785163/how-do-i-get-git-to-display-the-changes-in-vim-as-hg-does-with-the-hgeditor-scri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!