2

我正在尝试设置几个地图以快速解决合并冲突。这是我的代码:

func! DiffAccept(w)
  diffget a:w
  diffupdate
  normal ]c
endfunc

noremap dh :exec DiffAccept("//2")<CR>
noremap dl :exec DiffAccept("//3")<CR>

每次我尝试使用它时,我都会得到“a:w 没有匹配的缓冲区”。我显然错误地使用了这个变量,但是当我将行更改为“echo a:w”时它会按预期工作。

4

1 回答 1

5

Vim's evaluation rules are different than most programming languages. You need to use :execute in order to evaluate the (function argument) variable; otherwise, it's taken literally (as a buffer name):

execute 'diffget' a:w

PS: Prefer using :normal! (with !); this avoids interference from mappings.

于 2013-09-23T19:35:02.133 回答