0
  5 function VaptGet(command_arg, package_arg, ...)
  6     let vapt_command = ''
  7     let command_list = ['install', 'remove']
  8     echo command_list
  9     for commands in command_list:
 10         if commands == a:command_arg:
 11             let vapt_command = commands
 12         endif
 13     endfor
 14     echo a:package_arg
 15     echo "hello world"
 16 endfunction
 17 command! -nargs=* VaptGet call VaptGet(<f-args>)

当我运行时:

:VaptGet install tab

我得到:

['install', 'remove']
Error detected while processing function VaptGet:
line    4:
E121: Undefined variable: command_list:
E15: Invalid expression: command_list:
tab
hello world

有人可以告诉我为什么command_list缺少 var

4

1 回答 1

0

forVim 在循环和其他结构中不使用冒号:

for commands in command_list
    if commands == a:command_arg
        let vapt_command = commands
    endif
endfor
于 2013-01-17T03:37:50.857 回答