对于for-in结构中的vim脚本很奇怪

时间:2013-01-15 09:40:48

标签: vim

  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

1 个答案:

答案 0 :(得分:0)

Vim不在for循环和其他构造中使用冒号:

for commands in command_list
    if commands == a:command_arg
        let vapt_command = commands
    endif
endfor