Vim-在mercurial中提交时显示差异;
在myVim-在mercurial中提交时显示差异;,vim,mercurial,diff,hook,commit,Vim,Mercurial,Diff,Hook,Commit,在my.hgrc中,我可以提供一个编辑器或命令来启动带有提交选项的编辑器 我想写一个方法或别名来启动$hgci,它不仅会在Vim中打开消息,而且会拆分窗口并在那里打印出$hg diff 我知道我可以使用+{command}选项为vim提供参数。因此,启动$vim“+vsplit”会进行拆分,但任何其他选项都会转到第一个打开的窗口。所以我假设我需要一个特定的函数,但我没有编写自己的Vim脚本的经验 脚本应: 使用空缓冲区打开新的垂直拆分(可能使用vnew) 在空缓冲区中启动:。!汞差异 将空缓冲
.hgrc
中,我可以提供一个编辑器或命令来启动带有提交选项的编辑器
我想写一个方法或别名来启动$hgci
,它不仅会在Vim中打开消息,而且会拆分窗口并在那里打印出$hg diff
我知道我可以使用+{command}
选项为vim提供参数。因此,启动$vim“+vsplit”
会进行拆分,但任何其他选项都会转到第一个打开的窗口。所以我假设我需要一个特定的函数,但我没有编写自己的Vim脚本的经验
脚本应:
- 使用空缓冲区打开新的垂直拆分(可能使用
)vnew
- 在空缓冲区中启动
:。!汞差异
- 将空缓冲区文件类型设置为diff
:设置ft=diff
function! HgCiDiff()
vnew
:.!hg diff
set ft=diff
endfunction
在.hgrc
中,我添加了选项:editor=vim“+HgCiDiff()”
这是一种工作方式,但我希望拆分窗口位于右侧(现在它在左侧打开),mercurial消息位于焦点窗口。也可以将:wq
设置为:wq:q!的临时快捷方式代码>(假设mercurial消息是集中的)
有什么建议可以让它更有用,更不臃肿
更新:我发现用右下方的vnew
更改会打开右侧的差异。编辑
嗯,我想这可能不是你二读时想要的。我知道您需要一个多文件(统一)差异。我真的希望使用一个支持hg的UI工具和一个单独的vim编辑器来提交消息。很抱歉
如果您还不知道VCSCommand+Hg+Vim,我将保留“原始”响应:
我选择的武器是用
你会的
:VCSVimDiff
根据回购协议版本进行拆分(也与Leadercv)
:VCSVimDiff
与特定版本进行比较
所以我扩展了自己的代码:
function! HgCiDiff()
"In .hgrc editor option I call vim "+HgCiDiff()"
"It opens new split with diff inside
rightbelow vnew
:.!hg diff
set ft=diff
saveas! /tmp/hgdiff.txt
execute "normal \<c-w>w"
endfunction
我的解决方案由三个vim文件组成。它不需要更改hg配置,只显示您正在提交的文件的差异,如果您使用了hg commit file1 file2
:
~/.vim/ftdetect/hg.vim
au BufRead,BufNewFile /tmp/hg-editor-*.txt set filetype=hg
" Vim syntax file
" Language: hg commit file
" Maintainer: Marius Gedminas <marius@gedmin.as>
" Filenames: /tmp/hg-editor-*.txt
" Last Change: 2012 July 8
" Based on gitcommit.vim by Tim Pope
if exists("b:current_syntax")
finish
endif
syn case match
syn sync minlines=50
if has("spell")
syn spell toplevel
endif
syn match hgComment "^HG: .*"
hi def link hgComment Comment
let b:current_syntax = "hg"
" Show diff while editing a Mercurial commit message
" Inspired by http://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
" and Michael Scherer' svn.vim
function! HgCiDiff()
let i = 0
let list_of_files = ''
while i <= line('$') && getline(i) != 'HG: --'
let i = i + 1
endwhile
while i <= line('$')
let line = getline(i)
if line =~ '^HG: \(added\|changed\)'
let file = substitute(line, '^HG: \(added\|changed\) ', '', '')
let file = "'".substitute(file, "'", "'\''", '')."'"
let list_of_files = list_of_files . ' '.file
endif
let i = i + 1
endwhile
if list_of_files == ""
return
endif
pclose
new
setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
silent exec ':0r!hg diff ' . list_of_files
setlocal nomodifiable
goto 1
redraw!
" nooo idea why I have to do this
syn enable
endfunction
call HgCiDiff()
~/.vim/syntax/hg.vim
au BufRead,BufNewFile /tmp/hg-editor-*.txt set filetype=hg
" Vim syntax file
" Language: hg commit file
" Maintainer: Marius Gedminas <marius@gedmin.as>
" Filenames: /tmp/hg-editor-*.txt
" Last Change: 2012 July 8
" Based on gitcommit.vim by Tim Pope
if exists("b:current_syntax")
finish
endif
syn case match
syn sync minlines=50
if has("spell")
syn spell toplevel
endif
syn match hgComment "^HG: .*"
hi def link hgComment Comment
let b:current_syntax = "hg"
" Show diff while editing a Mercurial commit message
" Inspired by http://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
" and Michael Scherer' svn.vim
function! HgCiDiff()
let i = 0
let list_of_files = ''
while i <= line('$') && getline(i) != 'HG: --'
let i = i + 1
endwhile
while i <= line('$')
let line = getline(i)
if line =~ '^HG: \(added\|changed\)'
let file = substitute(line, '^HG: \(added\|changed\) ', '', '')
let file = "'".substitute(file, "'", "'\''", '')."'"
let list_of_files = list_of_files . ' '.file
endif
let i = i + 1
endwhile
if list_of_files == ""
return
endif
pclose
new
setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
silent exec ':0r!hg diff ' . list_of_files
setlocal nomodifiable
goto 1
redraw!
" nooo idea why I have to do this
syn enable
endfunction
call HgCiDiff()
Vim语法文件
“语言:hg提交文件
“维护者:马吕斯·格德米纳斯
“文件名:/tmp/hg编辑器-*.txt
“最后更改:2012年7月8日
“基于Tim Pope的gitcommit.vim
如果存在(“b:当前_语法”)
完成
恩迪夫
同步大小写匹配
同步最小线=50
如果有(“拼写”)
高级拼写
恩迪夫
同步匹配注释“^HG:.*”
高清链接评论
设b:current_syntax=“hg”
~/.vim/ftplugin/hg.vim
au BufRead,BufNewFile /tmp/hg-editor-*.txt set filetype=hg
" Vim syntax file
" Language: hg commit file
" Maintainer: Marius Gedminas <marius@gedmin.as>
" Filenames: /tmp/hg-editor-*.txt
" Last Change: 2012 July 8
" Based on gitcommit.vim by Tim Pope
if exists("b:current_syntax")
finish
endif
syn case match
syn sync minlines=50
if has("spell")
syn spell toplevel
endif
syn match hgComment "^HG: .*"
hi def link hgComment Comment
let b:current_syntax = "hg"
" Show diff while editing a Mercurial commit message
" Inspired by http://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
" and Michael Scherer' svn.vim
function! HgCiDiff()
let i = 0
let list_of_files = ''
while i <= line('$') && getline(i) != 'HG: --'
let i = i + 1
endwhile
while i <= line('$')
let line = getline(i)
if line =~ '^HG: \(added\|changed\)'
let file = substitute(line, '^HG: \(added\|changed\) ', '', '')
let file = "'".substitute(file, "'", "'\''", '')."'"
let list_of_files = list_of_files . ' '.file
endif
let i = i + 1
endwhile
if list_of_files == ""
return
endif
pclose
new
setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
silent exec ':0r!hg diff ' . list_of_files
setlocal nomodifiable
goto 1
redraw!
" nooo idea why I have to do this
syn enable
endfunction
call HgCiDiff()
编辑Mercurial提交消息时显示差异
“灵感来自http://stackoverflow.com/questions/8009333/vim-show-diff-on-commit-in-mercurial
“还有Michael Scherer的svn.vim
函数!HgCiDiff()
设i=0
让列表中的文件=“”
而我以下是我基于马吕斯·格德米纳斯和杰克利奥版本的变化:
function! HgCiDiff()
" find files that were changed (not interested in added or deleted)
let changed_files = []
let pattern = '\vHG: changed \zs(.+)\ze'
while search("HG: changed", "W") > 0
let line_text = getline(line("."))
call add(changed_files, matchstr(line_text, pattern))
endwhile
let diff_cmd = "hg diff " . join(changed_files, " ")
" Reset cursor to beginning of the buffer
call cursor(1, 1)
rightbelow vnew
setlocal buftype=nofile
let diff_output = system(diff_cmd)
call append(0, split(diff_output, "\n"))
" Reset cursor to beginning of the buffer
call cursor(1, 1)
setlocal ft=diff
wincmd p
setlocal spell spelllang=en_us
cnoremap wq wqa
cnoremap q qa!
startinsert
endfunction
谢谢,不,我不知道VCSCommand,它是一个很棒的工具,但你是对的。这不是我想要的:)两条评论:1)最后一行可以改为“wincmd w”或更准确地说,“wincmd p”,两者都可以。2)你可能想使用“setlocal”而不是“set”“用于文件类型。3) 除非您明确希望将差异保存到/tmp/hgdiff.txt,否则您可以改为“setlocal buftype=nofile”。4)您可以添加“cnoremap wq wqa”以实现最后的目标。(无法编辑以前的评论)您可能需要执行类似于静默的操作!setlocal ft=diff PREVIEWINDOW bufhidden=delete nobackup noswf NOBUUFLISTED nowrap buftype=nofile
,而不仅仅是set ft=diff
(取自~/.vim/ftplugin/svn.vim
)。另外,当您编辑与/tmp/hg editor-*.txt
匹配的文件时,最好让它运行,即将其设置为自动命令。啊,我不知道您可以以这种方式嵌套设置参数。相关问题第一个版本有一个可怕的bug,它假设hg会忽略“hg:”注释块之后的所有内容,并将diff直接包含在同一个缓冲区中(就像git commit-v一样)。这使得hg在提交消息中包含了整个diff。哎呀。通过一些添加,我可以看到我自己在使用这个:)其中一个是拼写检查器setlocal spell spelllang=en_-us,它还更新了我自己的代码,并进行了一些额外的修复。