Vim - 在 Mercurial 中显示提交的差异;
在我的 .hgrc 中,我可以提供一个编辑器或一个命令来启动带有提交选项的编辑器。
我想编写一个启动 $ hg ci
的方法或别名,它不仅会在 Vim 中打开消息,还会分割窗口并打印出 $ hg diff
。
我知道我可以使用 +{command}
选项向 vim 提供参数。因此启动 $ vim "+vsplit" 会进行分割,但任何其他选项都会转到第一个打开的窗口。所以我假设我需要一个特定的功能,但我没有编写自己的 Vim 脚本的经验。
该脚本应该:
- 使用空缓冲区打开新的垂直分割(可能使用
vnew
) - 在空缓冲区启动
:.!hg diff
- 将空缓冲区文件类型设置为 diff
: set ft=diff
我已经编写了这样的函数:
function! HgCiDiff()
vnew
:.!hg diff
set ft=diff
endfunction
并且在 .hgrc
中我添加了选项: editor = vim "+HgCiDiff()"
作品,但我想要分割窗口将位于右侧(现在它在左侧打开),而 Mercurial 消息将成为焦点窗口。还可以将 :wq
设置为 :wq
的临时快捷方式(假设 Mercurial 消息是焦点)。
有什么建议可以让它更有用并且不那么笨重吗?
更新:我发现vim 分割指南 因此用 rightbelow vnew
更改 vnew
会在右侧打开 diff。
In my .hgrc
I can provide an editor or a command to launch an editor with options on commit.
I want to write a method or alias that launches $ hg ci
, it would not only open up message in Vim, but also would split window and there print out $ hg diff
.
I know that I can give parameters to vim by using +{command}
option. So launching $ vim "+vsplit"
does the split but any other options goes to first opened window. So I assume i need a specific function, yet I have no experience in writing my own Vim scripts.
The script should:
- Open new vertical split with empty buffer (with
vnew
possibly) - In empty buffer launch
:.!hg diff
- Set empty buffer file type as diff
:set ft=diff
I've written such function:
function! HgCiDiff()
vnew
:.!hg diff
set ft=diff
endfunction
And in .hgrc
I've added option: editor = vim "+HgCiDiff()"
It kind of works, but I would like that splited window would be in right side (now it opens up in left) and mercurial message would be focused window. Also :wq
could be setted as temporary shortcut to :wq<CR>:q!
(having an assumption that mercurial message is is focused).
Any suggestions to make this a bit more useful and less chunky?
UPDATE: I found vim split guide so changing vnew
with rightbelow vnew
opens up diff on the right side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
所以我扩展了自己的代码:
然而它错过了
:wq
映射为:wqa
,但使用:wqa
并不难。我的 vimrc 的来源位于这里: http://hg.jackleo.info/vim -configs/src/08df5cb9d143/vimrc
我的 hgrc 来源位于此处: http://hg.jackleo.info/ home-configs/src/22f5fb47a7d2/.hgrc
更新:按照兰迪·莫里斯的建议我更新了我的代码现在它就像我想要的那样工作了。谢谢!随着时间的推移,还添加了一些额外的功能。
So I expanded my own code:
Yet It missed
:wq
mapping as:wqa
, yet using:wqa
is not that hard.Sources of my vimrc is located here: http://hg.jackleo.info/vim-configs/src/08df5cb9d143/vimrc
Sources of my hgrc is located here: http://hg.jackleo.info/home-configs/src/22f5fb47a7d2/.hgrc
Update: as suggested by Randy Morris I updated my code and now it works just as I wanted. Thanks! Also added few extra features as the time went by.
编辑
嗯,我想这可能不是你第二次阅读时想要的。我知道您想要一个多文件(统一)差异。我真的会使用一个 hg-aware UI 工具和一个单独的 vim 编辑器来处理提交消息。对此感到抱歉。
如果您还不知道 VCSCommand + Hg + Vim,我将保留“原始”响应立场:
我选择的武器是使用
vcscommand.vim : CVS/SVN/SVK/git/hg/bzr 集成插件
你会
针对存储库版本进行 diffsplit(也使用 Leadercv)
以与特定修订版本进行比较。
Edit
Hmm I think this might not be what you are after on second reading. I understand you want a multi-file (unified) diff. I'd really use a hg-aware UI tool and a separate vim editor for the commit message. Sorry about that.
I'll leave the 'original' response stand in case you didn't know VCSCommand + Hg + Vim yet:
My weapon of choice is to abstract it all away with
vcscommand.vim : CVS/SVN/SVK/git/hg/bzr integration plugin
You would
to diffsplit against the repo version (also with Leadercv)
to compare against a specific revision.
我的解决方案由三个 vim 文件组成。它不需要 hg 配置更改,并且仅显示您正在提交的文件的差异(如果您使用过
hg commit file1 file2
:~/.vim/ftdetect/hg .vim
~/.vim/syntax/hg.vim
~/.vim/ftplugin/hg.vim
My solution consists of three vim files. It doesn't require hg configuration changes, and only shows the diff for the files you're committing, if you've used
hg commit file1 file2
:~/.vim/ftdetect/hg.vim
~/.vim/syntax/hg.vim
~/.vim/ftplugin/hg.vim
这是我基于 Marius Gedminas 和 JackLeo 版本的变体:
Here's my variation based on Marius Gedminas and JackLeo's versions: