如何使用Vim快速查看Mercurial或Git的变化

发布于 2024-10-07 12:00:05 字数 69 浏览 0 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

万劫不复 2024-10-14 12:00:05

编辑 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:

enter image description here

你是年少的欢喜 2024-10-14 12:00:05

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

救赎№ 2024-10-14 12:00:05

尝试 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.

巷子口的你 2024-10-14 12:00:05

一种方法是执行以下操作:

:!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 type u to undo the addition. This works nicely too, esp if you want to yank some text from HEAD

淡淡的优雅 2024-10-14 12:00:05

有一个关于同时使用 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.

南冥有猫 2024-10-14 12:00:05

怎么样(不需要插件):

:new | r ! hg annotate -un #

这对当前缓冲区的文件名运行hg annotate,然后将输出转储到新缓冲区中。

这种形式的命令显然不是 git 和 hg 特有的。您可以通过这种方式捕获任何 shell 命令的结果。

How about this (no plugins required):

:new | r ! hg annotate -un #

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.

指尖凝香 2024-10-14 12:00:05

这适用于 Hg 和 Git:
https://github.com/mhinz/vim-signify

This works for both Hg and Git:
https://github.com/mhinz/vim-signify

我一向站在原地 2024-10-14 12:00:05

对于 Mercurial,fugitive 的等价物是 lawrenciumhttp://bolt80 .com/lawrencium

它支持并排比较和突出显示的类似 diff 的视图(基本上是您从 hg diff 获得的内容) (

免责声明:我是作者)

For Mercurial, an equivalent of fugitive is lawrencium: http://bolt80.com/lawrencium

It supports both side-by-side diff and a highlighted diff-like view (basically what you get from hg diff <file>.

(disclaimer: I'm the author)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文