2

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".

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Greg Wilbur
  • 633
  • 5
  • 9

1 Answers1

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • +1 btw @Ingo, `exec 'foo '.'bar'` and `exec 'foo' 'bar'`, which format do you prefer? – Kent Sep 23 '13 at 19:44