简体   繁体   English

我如何让git像hg一样用hgeditor脚本显示vim中的变化?

[英]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 ). mercurial中一个有趣的功能是能够查看将在vim拆分中提交的更改(请参阅DiffsInCommitMessageInVIM )。

Any hint on how to do so with git ? 如何使用git提示?

Assuming you've got syntax enabled, Vim detects git commit messages as a filetype. 假设您已启用语法,Vim会将git提交消息检测为文件类型。 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). 不太明显的部分是它还有一个git提交(和其他git东西)的文件类型插件。 Make sure you have those enabled ( filetype plugin on ), and then there will be a helpful command defined: DiffGitCached . 确保启用了这些( filetype plugin on ),然后将定义一个有用的命令: 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! 文件类型插件存储在/vimXX/ftplugin/git*.vim中,例如/usr/share/vim/vim70/ftplugin/gitcommit.vim ,如果你很想看看!

I've modified the HGEDITOR.SH script to support Git, you can clone it here: 我修改了HGEDITOR.SH脚本以支持Git,你可以在这里克隆它:

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

Enjoy! 请享用!

I highly recommend tpopes's vim-fugitive plugin for working with git. 我强烈推荐使用tpopes的vim-fugitive插件来处理git。

You can find it here 你可以在这里找到它

I use Pierre Habouzit's git.vim from www.vim.org. 我从www.vim.org使用Pierre Habouzit的 git.vim。 Drop it into ~/.vim/ftplugin and you should be all set (assuming the usual filetype plugin indent on in your ~/.vimrc). 把它放到〜/ .vim / ftplugin中你应该全部设置(假设〜/ .vimrc中通常的filetype plugin indent on )。

If you're using git 2.9 and above, you can get this behaviour by running git config --global commit.verbose true . 如果您正在使用git 2.9及更高版本,则可以通过运行git config --global commit.verbose true来获得此行为。

Source: this answer . 来源: 这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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