“current_compiler”变量值的重要性

时间:2011-03-30 21:18:12

标签: vim

Vim的编译器插件应该将变量current_compiler的值设置为某个值。除非它们旨在扩充现有的编译器插件,否则它们也应该提前退出(如果已经定义了该变量)。是否要使用变量的值?它应该设置为编译器插件文件的基名吗? (例如$VIMRUNTIME/compiler/foo.vim - > foo

documentation有这样说:

To support older Vim versions, the plugins always use "current_compiler" and
not "b:current_compiler".  What the command actually does is the following:

- Delete the "current_compiler" and "b:current_compiler" variables.
- Define the "CompilerSet" user command.  With "!" it does ":set", without "!"
  it does ":setlocal".
- Execute ":runtime! compiler/{name}.vim".  The plugins are expected to set
  options with "CompilerSet" and set the "current_compiler" variable to the
  name of the compiler.
- Delete the "CompilerSet" user command.
- Set "b:current_compiler" to the value of "current_compiler".
- Without "!" the old value of "current_compiler" is restored.

引用的命令是:compiler。它的参数变为上面使用的{name}

writing compiler plugins上的条目不提供其他信息,上述条目涵盖了vim帮助数据库中字符串current_compiler的所有实例(根据:lhelpgrep current_compiler

1 个答案:

答案 0 :(得分:0)

您可以在~.vim/after/ftplugin/<filetype>.vim中为文件类型预先选择特定的编译器。 因为无论何时加载缓冲区(例如,当移动:args时)都会重新获取,所以建议仅在尚未设置的情况下设置编译器(即仅在第一次加载时)。否则,切换缓冲区可能会覆盖任何已更改的编译器,并且可能会一直打印(并且需要确认)编译器设置时的消息。