Answers:
我猜vim没有内置的这个功能,所以我在Python中编写了一个函数:
def DiffJump():
"""
Based on the current position of the cursor, jump to the appropriate
file/line combination.
"""
row, col = vim.current.window.cursor
buf = vim.current.window.buffer
offt = -1
havehunk = False
for lnum in xrange(row-1, -1, -1):
line = buf[lnum]
if line.startswith("@@"):
if havehunk:
continue
havehunk = True
atat, minus, plus, atat = line.split()
baseline = int(plus[1:].split(",")[0])
realline = baseline + offt
elif line.startswith("+++"):
fname = line[4:].split("\t")[0]
vim.command("e +{line:d} {fname}"
.format(line=realline, fname=fname))
break
elif not havehunk and line.startswith(" ") or line.startswith("+"):
offt += 1
elif line.startswith("-"):
pass
else:
print "No hunk found."