문제

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