Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top