如何使用Vim快速查看Mercurial或Git的变化
当我在 Vim 中编辑文件时,我想快速突出显示自上次提交以来所做的任何更改,同时仍然能够编辑该文件。有什么可以接近这样做吗?
As I'm editing a file in Vim, I would like to quickly highlight any changes I have made since my last commit, while still being able to edit the file. Is there anything that comes close to doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
编辑 2020-01-23:快速搜索,仅供参考,发现还有另一个插件似乎与 VCS 无关: https:// /github.com/mhinz/vim-signify
有一个新插件可以执行此操作: vim-gitgutter 。每当您保存文件时,它都会将更改放入 Vim 装订线中。下面是它的实际效果:
Edit 2020-01-23: Searched quickly and FYI saw that there's another plugin that seems more VCS agnostic: https://github.com/mhinz/vim-signify
There's a new plugin that does this: vim-gitgutter. It puts the changes in the Vim gutter whenever you save the file. Here's what it looks like in action:
看看 Tim Pope 的 fugitive.vim 插件。
我是一个 git 纯粹主义者,通常会进入 git 命令行,但是当我在 vim 中时,我发现这完成了我需要做的大部分事情,但我仍然可以直接调用 git 命令。
Have a look at Tim Pope's fugitive.vim plugin.
I'm a git purist and usually drop into the command line for git, but when I'm in vim I find that this does most of what I need to do and yet I can still call git commands directly.
尝试 vcscommand 插件,使用
:VCSVimDiff
查看与当前版本的差异(支持 hg 和 git,可能还支持其他一些 SCM 系统)和内部:bdelete
(:bd
) (当然在打开的缓冲区上,而不是已经存在)以停止比较。如果您使用的是 gentoo,可以在存储库中找到它:app-vim/vcscommand
。Try vcscommand plugin, use
:VCSVimDiff
to view differencies with current revision (supports both hg and git, probably some other SCM systems as well) and internal:bdelete
(:bd
) (on opened buffer of course, not on already existing) to stop diffing. If you are using gentoo, it is available in the repository:app-vim/vcscommand
.一种方法是执行以下操作:
:!git diff
HEAD
相比的更改(对所有文件)这将显示与执行单个文件的
:!git diff path/to/file
这是一种快速的方法,无需切换不同的应用程序,也无需安装任何插件(这在某些您没有的系统上并不总是容易做到)控制)。
它不会给你“内联”突出显示,但应该可以正常工作。
另一种快速完成此操作的方法是执行
:r !git diff
查看更改,然后输入u
撤消添加。这也很好用,特别是如果你想从HEAD
中提取一些文本one method is to do the following:
:!git diff
This will show the changes (to all files) in comparison to
HEAD
to do a single file
:!git diff path/to/file
this is a quick way of doing it without switching different apps nor installing any plugins (which isn't always easy to do on some systems that you don't have control over).
it wont give you 'inline' highlighting but should work ok.
another way to do it quickly is to do a
:r !git diff
take a look at the changes then typeu
to undo the addition. This works nicely too, esp if you want to yank some text fromHEAD
有一个关于同时使用 git 和 vim 的网站:
http://www.osnews.com/story/ 21556/Using_Git_with_Vim
我使用 git.vim,每次需要比较时,我都可以使用
\gd
检查它。There is a site on using git and vim together:
http://www.osnews.com/story/21556/Using_Git_with_Vim
I use the git.vim one, and every time I need a diff I can check it with
\gd
.怎么样(不需要插件):
这对当前缓冲区的文件名运行
hg annotate
,然后将输出转储到新缓冲区中。这种形式的命令显然不是 git 和 hg 特有的。您可以通过这种方式捕获任何 shell 命令的结果。
How about this (no plugins required):
This run
hg annotate
on the filename of the current buffer, then dumps the output in a new buffer.This form of command is obviously not specific to git and hg. You can capture the results of any shell command this way.
这适用于 Hg 和 Git:
https://github.com/mhinz/vim-signify
This works for both Hg and Git:
https://github.com/mhinz/vim-signify
对于 Mercurial,
fugitive
的等价物是lawrencium
:http://bolt80 .com/lawrencium它支持并排比较和突出显示的类似
diff
的视图(基本上是您从hg diff
获得的内容) (免责声明:我是作者)
For Mercurial, an equivalent of
fugitive
islawrencium
: http://bolt80.com/lawrenciumIt supports both side-by-side diff and a highlighted
diff
-like view (basically what you get fromhg diff <file>
.(disclaimer: I'm the author)