以下是一个例子:
function! Mynumber(arg)
echo line(".") . " " . a:arg
endfunction
当你1,3call Mynumber(getline("."))
时,它会打印行号和当前缓冲区的前三行中的每一行。
答案 0 :(得分:5)
变量的前缀a:
表示此变量属于其出现的函数的参数列表(参数)。
另见:help internal-variables
There are several name spaces for variables. Which one is to be used is
specified by what is prepended:
(nothing) In a function: local to a function; otherwise: global
buffer-variable b: Local to the current buffer.
window-variable w: Local to the current window.
tabpage-variable t: Local to the current tab page.
global-variable g: Global.
local-variable l: Local to a function.
script-variable s: Local to a :source'ed Vim script.
function-argument a: Function argument (only inside a function).
vim-variable v: Global, predefined by Vim.
答案 1 :(得分:1)
“当你编写一个带参数的Vimscript函数时,你总是需要用这些参数作为前缀:当你用它们告诉Vim它们在参数范围内时。”
来源(强烈推荐阅读):http://learnvimscriptthehardway.stevelosh.com/chapters/24.html