I'm trying to set up a couple of maps to quickly go through merge conflicts. Here's my code:

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

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

Every time I try to use this I get "No matching buffer for a:w". I'm clearly using this variable wrong, but it acts as expected when I change the line to "echo a:w".

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top